August Shi created PDFBOX-2784:
----------------------------------

             Summary: Removing unnecessary object creation
                 Key: PDFBOX-2784
                 URL: https://issues.apache.org/jira/browse/PDFBOX-2784
             Project: PDFBox
          Issue Type: Improvement
          Components: FontBox, PDModel
         Environment: Ubuntu
            Reporter: August Shi
            Priority: Minor
             Fix For: 2.0.0


I discovered several performance inefficiencies in the current version of the 
code. I found these after using PDFReader to open a 10-page PDF and clicking 
all the menu items.

First, in org.apache.fontbox.afm.CharMetric, a new ArrayList object is created 
and assigned to the instance field "ligatures" upon creation of an instance. 
During execution, elements are added into the array, but the ArrayList itself 
is never read from. In fact, the getter for the field "ligatures" is never 
invoked in the rest of the code. It seems like this ArrayList object is useless 
since its data is never actually used. I removed this field and other 
corresponding methods to avoid creating a useless object. I also removed calls 
to add elements to the "ligatures" field found in 
org.apache.fontbox.afm.AFMParser.

Second, in the same AFMParser class, a new BoundingBox object is created and  
stored in the field "boundingBox" in an instance of CharMetirc. I looked at the 
 code and found out that the purpose of creating this object is merely for  
calculating the height of the bounding box, as seen in 
org.apache.fontbox.afm.FontMetrics. To avoid creating the object, I introduced 
a field "boundingBoxHeight" in class CharMetric to store the information 
instead of storing the BoundingBox object. I also introduced getter and setter 
functions for this new field. I then modified the code in FontMetrics to invoke 
this new getter for the height value. I found a similar "boundingBox" field in 
org.apache.fontbox.ttf.GlyphData with the same characteristics (only being used 
for its height) and added a function to obtain the BoundingBox's height. 
Similary, I modified code in org.apache.pdfbox.pdmodel.font.PDTrueTypeFont to 
use this height getter instead of getting the BoundingBox instance.

I will attach all the files that I changed.




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to