[CDRIVER-2414] bson_iter{_init}_find should have length taking overloads Created: 02/Dec/17  Updated: 28/Oct/23  Resolved: 26/Dec/17

Status: Closed
Project: C Driver
Component/s: libbson, Performance
Affects Version/s: None
Fix Version/s: 1.10.0

Type: Task Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: Xiangyu Yao (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CXX-1500 document::view::find should use bson_... Closed
Related
is related to CXX-1476 Element search stops prematurely due ... Closed
is related to CXX-992 bsoncxx::document::view::find() shoul... Closed
is related to CDRIVER-2360 decimal128 and regex functions that a... Closed
Epic Link: libbson iter api
Backwards Compatibility: Fully Compatible

 Description   

If you have a string held in not-guaranteed-null-terminated storage, you cannot currently use that string directly to search within a bson_t with bson_iter_find or bson_iter_init_find, and instead must heap allocate a known-to-be-null-terminated temporary string to pass in.

The C++ driver stopped using bson_iter_init_find in CXX-992 to avoid the overhead of this temporary allocation, and began walking and comparing keys directly. Unfortunately, the implementation was buggy, leading to CXX-1476.

If the two forms of find had overloads that took an associated length for the key, then the C++ driver could use those rather than re-implementing key comparison itself.

If this is not viable for some reason, an alternative would be to make an overload of bson_iter_key that returned the key length in an out parameter. This would allow the C++ driver to avoid a required (though currently not present) call to strlen on the result of bson_iter_key, which is almost certainly redundant work to recover information that the C driver has already determined.

It may make sense to implement the length returning form of bson_iter_key even if the bson_iter_find changes are made anyway, as searching in BSON is very common, and the C driver should surface all information available that may assist clients.



 Comments   
Comment by Githook User [ 14/Dec/17 ]

Author:

{'name': 'Xiangyu Yao', 'email': 'xiangyu.yao24@gmail.com', 'username': 'xy24'}

Message: CDRIVER-2414 add bson_iter_[find/init_find]_w_len functions
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/39debee5295997726e66efc15dbde8df23af142d

Generated at Wed Feb 07 21:15:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.