Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2442

Increase StringBuilder capacity during instantiation

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor - P4 Minor - P4
    • None
    • 2.7.2
    • BSON, Performance
    • None
    • All
    • Fully Compatible

    Description

      MongoDB.Bson/IO/JsonWriter.cs

      Regarding the following function:

      private string EscapedString(string value)

       

      and the following line of code:

      var sb = new StringBuilder(value.Length);

       

      This StringBuilder object is being created because the string named "value" needs escaping. It is unknown at this point exactly how many characters need escaping, but AT MINIMUM there is one. This means the new escaped string length will be larger than original string length by at least one character, and the StringBuilder constructor capacity parameter should reflect this logic. Without this change, the StringBuilder object is GUARANTEED to allocate and chain together a new StringBuilder object under the hood as it increases it's capacity to handle the larger escaped string.

      Attachments

        Activity

          People

            Unassigned Unassigned
            Achilles1515 Dane Owens
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: