Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-32422 convert StringData to std::string_view
  3. SERVER-48429

Remove StringData::ComparatorInterface from StringData

    • Service Arch
    • Fully Compatible

      StringData::ComparatorInterface and most of its callers can be improved in several respects. I want to open this ticket to give the StringData::ComparatorInterface some attention. It's used in some very important places.

      Move it out of the StringData class to be a first-class type. StringData::ComparatorInterface is not part of what StringData is. It's just one particular thing you can do with StringData. We already have a separate file for its definition, `mongo/base/string_data_comparator_interface.h`, so we can essentially rename `StringData::ComparatorInterface` to `StringDataComparator` in that file. We can remove "Interface" from the name. I'm looking at the typedefs:
      StringDataUnorderedSet
      StringDataUnorderedMap

      And they are hard to use correctly because their hasher and key_eq functors are stateful, so a factory function is needed, and the functors provided have lifetime caveats on an underlying StringData::ComparatorInterface everybody just uses the singleton kInstance, so the whole thing can just be a family of matched stateless functors for every use in the codebase. Many can now be migrated to use stdx::unordered_map and stdx::unordered_set and be more efficient.

      The StringDataComparatorInterface is missing an equal virtual function. It has a compare and a hash_combine but no equal. This means that doing hash container lookups will have to use compare, which is potentially far more expensive than == on StringData, as equality can short-circuit in the case of unequal string lengths.

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: