[
https://issues.apache.org/jira/browse/PDFBOX-4895?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17147232#comment-17147232
]
Alfred commented on PDFBOX-4895:
--------------------------------
I was working on a change for COSFloat and realized we don't have to try and
parse it as a float if it was not a valid long.
We already verified it only has digits, so, when "return
COSInteger.get(Long.parseLong(number));" throws NumberFormatException, it
really is because the number is larger than a long can carry.
We should not waste time trying to parse a COSFloat because it will only result
in -MAX_VALUE or +MAX_VALUE.
In theory, this will improve the performance further:
{code:java}
try
{
return COSInteger.get(Long.parseLong(number));
}
catch( NumberFormatException e )
{
// might be a huge number, see PDFBOX-3116
char digit = number.charAt(0);
if (digit == '-')
{
return new COSFloat(-Float.MAX_VALUE);
}
return new COSFloat(Float.MAX_VALUE);
}
{code}
Here's a new patch: [^PDFBOX-4895-b.patch]
And the new review: https://diffy.org/diff/0deq6icwg8y48242apjp5y7gb9
> Faster COSNumber
> ----------------
>
> Key: PDFBOX-4895
> URL: https://issues.apache.org/jira/browse/PDFBOX-4895
> Project: PDFBox
> Issue Type: Improvement
> Affects Versions: 2.0.20, 3.0.0 PDFBox
> Reporter: Alfred
> Priority: Trivial
> Labels: Optimization
> Attachments: PDFBOX-4895-b.patch, PDFBOX-4895.patch
>
>
> A small improvement can be made to COSNumber when checking if it's float.
> Current version uses indexOf twice, to check for '.' or 'e'.
> We can do that in one scan.
>
> Each call will scan through the entire string.
> We only have to scan until we find the chars, and stop if found.
>
> I found while profiling the code that the method gets called a lot, so the
> improvement makes a a bit of a difference.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]