Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2230

Create new Document constructor taking initial capacity of LinkedHashMap

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • 3.2.2
    • API, BSON
    • None
    • Fully Compatible

    Description

      Currently, when Document class is initialized, it doesn't allow setting `initialCapacity` of internal LinkedHashMap so, that value gets set to 16 everytime. This doesn't work well if I already know number of entries going to be inserted / appended. If number of entries are are less than 16 then, it's kind of creating internal linked list table with bigger size or if entries are greater than 16, it's guaranteed to do `resize()`.

      So, it would be nice if Document class exposes new constructor with initial capacity of internal LinkedHashMap.

      /**
       * Creates an empty Document instance with custom intial capacity
       */
      public Document(int initialCapacity) {
          documentAsMap = new LinkedHashMap<String, Object>(initialCapacity);
      }
      

      Attachments

        Activity

          People

            ross@mongodb.com Ross Lawley
            ifx PRAJWAL TULADHAR
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: