Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-30172

Allow accessing StringData from a string-typed Value

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
    • Query

      The Value class currently exposes a getString() method, and has a private getStringData() method that does not do type checking.

      Many callers just need to read and compare the value of a string stored in a Value, so would benefit from the StringData version of this interface. We should expose a version of getStringData that does type checking. Since a StringData is just a reference to a string owned elsewhere, such a method could potentially be used incorrectly in a line of code such as:

      auto myString = doc["stringField"].getStringData();  // Returning pointer to memory about to be de-allocated.
      

      This should be avoided by deleting the r-value override of getStringData(). As part of this work, we should consider auditing existing callers of getString() to see if they could use getStringData() instead and see a performance improvement.

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: