[Lldb-commits] [PATCH] D23884: Add StructuredData unit tests; remove JSON parsing string copy

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Fri Aug 26 09:15:07 PDT 2016

zturner added a comment.

Actually it looks like `JSONParser` constructor takes a `StringRef` and then converts it to a `std::string` internally.  Why can't it just store the `StringRef` internally?  It doesn't modify the buffer, and incidentally it also keeps a `uint64_t` representing the "offset" into the string.  That's what a `StringRef` is.  an immutable buffer and an offset.  Each time you extract something, you just say `m_buffer = m_buffer.drop_front(n)`.

There is the `SetFilePos()` method, but it looks like it's only being used for two purposes:  1) To move forward, and 2) To reset the position to 0 after setting a new string in the extractor.  The first one is still possible with a `StringRef` by writing `extractor.skip(n)`, and the second one is still possible by writing `extractor.SetString(NewStringRef)`.


More information about the lldb-commits mailing list