Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-5451

Avoid exposing underlying byte array

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.0 PDFBox
    • 3.0.0 PDFBox
    • Parsing
    • None

    Description

      When creating a COSString the given byte array is cloned. As in most cases the array is just an intermediate object we should remove that to reduce the memory footprint.
      Furthermore the getBytes returns the internal byte array so that I don't see any reason not to use the given byte array itself instead of cloning it

      My first idea was to remove the clone when setting the value of a COSString to reduce the memory footprint. After some discussion we came to the conclusion that it would make sense to do so if COSStrings were immutable. But to make COSStrings immutable some refactoring is needed and I won't do that for 3.0.0.

      Saying that, I've reverted my first change and and added a clone in getBytes so that the underlying byte array isn't exposed at all.

      Attachments

        Activity

          People

            lehmi Andreas Lehmkühler
            lehmi Andreas Lehmkühler
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: