|
The current version of bsoncxx::document::view::find() is implemented in terms of bson_iter_init_find(). This implementation requires a call to string_view::to_string() (which performs an allocation), in order to conform to the bson_iter_t API (which expects null-terminated strings). See snippet below:
168 view::iterator view::find(stdx::string_view key) const {
|
169 bson_t b;
|
170 bson_iter_t iter;
|
171
|
172 if (!bson_init_static(&b, _data, _length)) {
|
173 return end();
|
174 }
|
175
|
176 if (bson_iter_init_find(&iter, &b, key.to_string().data())) {
|
177 return iterator(element(iter.raw, iter.len, iter.off));
|
178 }
|
179
|
180 return end();
|
181 }
|
This method could be rewritten to avoid the allocation by manually iterating the bson_iter_t to find the desired element, instead of relying on bson_iter_init_find().
Other calls to string_view::to_string() could possibly be audited to determine whether similar performance improvements could be gained elsewhere.
|