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

Change COSFloat.value to primitive type, do not use BigDecimal if not necessary

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0.0 PDFBox
    • 3.0.0 PDFBox
    • None
    • None
    • Patch

    Description

      Using the primitive type here uses both less memory and also reduces overhead because less boxing/unboxing needs to be done.

      I changed value from `private Float value` to `private final float`.

      I also changed the formatting code in two small details:

      1. using BigDecimal is really just necessary, if the value is formatted to scientific notation. Since Float.toString() is called anyway, we can check for presence of an exponent ('E') and if none is found, return the already created string.
      2. I removed the trimZeroes() method and let BigDecimal handle this so that the zeroes are removed before converting to a string.

      I left valueAsString to be computed lazily when the string representation is not already known in the constructor call. It would also be possible to make valueAsString final, but then it might be computed unnecessarily, if formatString() is never called on the instance.

      Attachments

        Activity

          People

            lehmi Andreas Lehmkühler
            axh Axel Howind
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: