Skip to content

Commit ca194ea

Browse files
committed
Disable to paging functionality of the parser, IFC files are now always entirely read into memory.
1 parent 89a6e73 commit ca194ea

2 files changed

Lines changed: 46 additions & 8 deletions

File tree

src/ifcparse/IfcFile.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
#include <fstream>
3131
#include <string>
3232

33-
const int BUF_SIZE = (128 * 1024 * 1024);
33+
// As of IfcOpenShell version 0.3.0 the paging functionality, which
34+
// loads a file on disk into multiple chunks, has been disabled.
35+
// It proved to be an inefficient way of working with large files,
36+
// as often these did not facilitate to be parsed in a sequential
37+
// manner efficiently, to enable the paging functionality uncomment
38+
// the following statement.
39+
//const int BUF_SIZE = (128 * 1024 * 1024);
3440

3541
namespace IfcParse {
3642
/// The File class represents a ISO 10303-21 IFC-SPF file in memory.
@@ -46,9 +52,11 @@ namespace IfcParse {
4652
char* buffer;
4753
unsigned int ptr;
4854
unsigned int len;
49-
unsigned int offset;
5055
void ReadBuffer(bool inc=true);
56+
#ifdef BUF_SIZE
57+
unsigned int offset;
5158
bool paging;
59+
#endif
5260
public:
5361
bool valid;
5462
bool eof;

src/ifcparse/IfcParse.cpp

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,43 @@ File::File(const std::string& fn) {
4444
stream.seekg(0,std::ios_base::end);
4545
size = (unsigned int) stream.tellg();
4646
stream.seekg(0,std::ios_base::beg);
47+
#ifdef BUF_SIZE
48+
offset = 0;
4749
paging = size > BUF_SIZE;
4850
buffer = new char[size < BUF_SIZE ? size : BUF_SIZE];
51+
#else
52+
buffer = new char[size];
53+
#endif
4954
ptr = 0;
50-
len = 0;
51-
offset = 0;
55+
len = 0;
5256
ReadBuffer(false);
5357
}
5458

5559
File::File(std::istream& f, int l) {
5660
eof = false;
5761
size = l;
62+
#ifdef BUF_SIZE
5863
paging = false;
64+
offset = 0;
65+
#endif
5966
buffer = new char[size];
6067
f.read(buffer,size);
6168
valid = f.gcount() == size;
6269
ptr = 0;
63-
len = l;
64-
offset = 0;
70+
len = l;
6571
}
6672

6773
File::File(void* data, int l) {
6874
eof = false;
6975
size = l;
76+
#ifdef BUF_SIZE
7077
paging = false;
78+
offset = 0;
79+
#endif
7180
buffer = (char*) data;
7281
valid = true;
7382
ptr = 0;
74-
len = l;
75-
offset = 0;
83+
len = l;
7684
}
7785

7886
void File::Close() {
@@ -84,13 +92,19 @@ void File::Close() {
8492
// Reads a chunk of BUF_SIZE in memory and increments cursor if requested
8593
//
8694
void File::ReadBuffer(bool inc) {
95+
#ifdef BUF_SIZE
8796
if ( inc ) {
8897
offset += len;
8998
stream.seekg(offset,std::ios_base::beg);
9099
}
100+
#endif
91101
eof = stream.eof();
92102
if ( eof ) return;
103+
#ifdef BUF_SIZE
93104
stream.read(buffer,size < BUF_SIZE ? size : BUF_SIZE);
105+
#else
106+
stream.read(buffer,size);
107+
#endif
94108
len = (unsigned int) stream.gcount();
95109
eof = len == 0;
96110
ptr = 0;
@@ -100,10 +114,13 @@ void File::ReadBuffer(bool inc) {
100114
// Seeks an arbitrary position in the file
101115
//
102116
void File::Seek(unsigned int o) {
117+
#ifdef BUF_SIZE
103118
if ( !paging ) {
119+
#endif
104120
ptr = o;
105121
if (ptr >= len) throw IfcException("Reading outside of file limits");
106122
eof = false;
123+
#ifdef BUF_SIZE
107124
} else if ( o >= offset && (o < (offset+len)) ) {
108125
ptr = o - offset;
109126
} else {
@@ -112,6 +129,7 @@ void File::Seek(unsigned int o) {
112129
stream.seekg(o,std::ios_base::beg);
113130
ReadBuffer(false);
114131
}
132+
#endif
115133
}
116134

117135
//
@@ -125,34 +143,46 @@ char File::Peek() {
125143
// Returns the character at specified offset
126144
//
127145
char File::Read(unsigned int o) {
146+
#ifdef BUF_SIZE
128147
if ( ! paging ) {
148+
#endif
129149
return buffer[o];
150+
#ifdef BUF_SIZE
130151
} else if ( o >= offset && (o < (offset+len)) ) {
131152
return buffer[o-offset];
132153
} else {
133154
stream.clear();
134155
stream.seekg(o,std::ios_base::beg);
135156
return stream.peek();
136157
}
158+
#endif
137159
}
138160

139161
//
140162
// Returns the cursor position
141163
//
142164
unsigned int File::Tell() {
165+
#ifdef BUF_SIZE
143166
return offset + ptr;
167+
#else
168+
return ptr;
169+
#endif
144170
}
145171

146172
//
147173
// Increments cursor and reads new chunk if necessary
148174
//
149175
void File::Inc() {
150176
if ( ++ptr == len ) {
177+
#ifdef BUF_SIZE
151178
if ( paging ) ReadBuffer();
152179
else {
180+
#endif
153181
eof = true;
154182
return;
183+
#ifdef BUF_SIZE
155184
}
185+
#endif
156186
}
157187
const char current = File::Peek();
158188
if ( current == '\n' || current == '\r' ) File::Inc();

0 commit comments

Comments
 (0)