[ 
https://issues.apache.org/jira/browse/PDFBOX-1654?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Fred Hansen updated PDFBOX-1654:
--------------------------------

    Attachment: XMLUtil-addPlus.patch

> Wasted work in XMLUtil.getNodeValue
> -----------------------------------
>
>                 Key: PDFBOX-1654
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1654
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.8.2
>         Environment: any
>            Reporter: Adrian Nistor
>              Labels: patch, performance
>         Attachments: XMLUtil-addPlus.patch, patch.diff, patchShort.diff
>
>
> The problem appears in version 1.8.2 and in revision 1497941.  I
> attached a two-line patch (patch.diff) that fixes it.
> In method "XMLUtil.getNodeValue", the loop over "children" keeps
> overriding "retval" with "next.getNodeValue()".  Therefore, only the
> last written value is visible out of the loop and all the other writes
> and iterations are not necessary.  The patch iterates from the end of
> "children" and breaks the first time when "retval" is set.
> The above fix (in patch.diff) is certainly correct (it's easy to see
> through code inspection), but I think we can have an even shorter
> patch (one line, in patchShort.diff): just break as soon as "retval"
> is set, without reversion the loop order.  patchShort.diff is correct
> only if there can be only one "Text" child, or if it doesn't matter
> which "Text" child is returned (the last, like in the original code,
> or the first, like in patchShort.diff).



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to