Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify how strings are read from DocsDB and ExternalVocabulary #6

Merged
merged 3 commits into from Apr 28, 2017
Merged

Simplify how strings are read from DocsDB and ExternalVocabulary #6

merged 3 commits into from Apr 28, 2017

Conversation

niklas88
Copy link
Member

Currently the words in the external vocabulary and the docs in DocsDB are turned into std::strings by creating a temporary heap allocated char array and constructing a std::string from that.

Instead we can use the contiguous memory guarantee introduced in C++11 to read directly into a string of the right size. When C++17 comes along we can even change this to use non-const .data() to make it cleaner.

While we are add it fix a comment.

Sadly until C++17 std::string::data() returns a const pointer and thus
we need to resort to the front() trick. We can fix this once C++17
is out.

NOTE: This is legal only due to the contiguous memory guarantee
introduced in C++11 see also:

http://stackoverflow.com/questions/33124479/does-stdstring-need-to-store-its-character-in-a-contiguous-piece-of-memory
@Buchhold
Copy link
Member

Hi Niklas, thanks for the patch. Looks great!

@Buchhold Buchhold merged commit c5f51b8 into ad-freiburg:master Apr 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants