Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2414

bson_iter{_init}_find should have length taking overloads

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.10.0
    • Affects Version/s: None
    • Component/s: libbson, Performance
    • Labels:
      None
    • Fully Compatible

      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.

            Assignee:
            xiangyu.yao@mongodb.com Xiangyu Yao (Inactive)
            Reporter:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: