Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-7983

Utils.toUTF8 uses larger buffer than necessary for holding UTF8 data

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.4, 6.0
    • Component/s: None
    • Labels:
      None

      Description

      Method in question:

      public static byte[] toUTF8(CharArr out) {
          byte[] arr = new byte[out.size() << 2]; // is 4x the real worst-case upper-bound?
          int nBytes = ByteUtils.UTF16toUTF8(out, 0, out.size(), arr, 0);
          return Arrays.copyOf(arr, nBytes);
        }
      

      The byte array should be at most out.size() * 3.

        Attachments

          Activity

            People

            • Assignee:
              shalinmangar Shalin Shekhar Mangar
              Reporter:
              shalinmangar Shalin Shekhar Mangar
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: