ReaderLcf: optimize DBString reading
MODIFY
src/lcf/reader_lcf.h
src/lcf/reader_lcf.h
@@ -221,6 +221,9 @@ public:
/** @return a buffer which can be reused for parsing */
std::vector<int32_t>& IntBuffer();
+ /** @return a buffer which can be reused for parsing */
+ std::string& StrBuffer();
+
private:
/** File-stream managed by this Reader. */
std::istream& stream;
@@ -232,6 +235,8 @@ private:
Encoder encoder;
/** A temporary buffer to be used in parsing */
std::vector<int32_t> buffer;
+ /** A temporary buffer to be used in parsing */
+ std::string str_buffer;
/**
* Converts a 16bit signed integer to/from little-endian.
@@ -273,6 +278,10 @@ inline std::vector<int32_t>& LcfReader::IntBuffer() {
return buffer;
}
+inline std::string& LcfReader::StrBuffer() {
+ return str_buffer;
+}
+
} //namespace lcf
#endif

MODIFY
src/reader_lcf.cpp
src/reader_lcf.cpp
@@ -191,8 +191,7 @@ void LcfReader::ReadString(std::string& ref, size_t size) {
}
void LcfReader::ReadString(DBString& ref, size_t size) {
- // FIXME: Relies on short string optimization
- std::string tmp;
+ auto& tmp = StrBuffer();
ReadString(tmp, size);
ref = DBString(tmp);
}

ReaderLcf: optimize DBString reading