Ignore:
Timestamp:
2024-01-23T15:17:43+01:00 (10 months ago)
Author:
GerdP
Message:

fix #23427 load session performance strongly depends on order of layers
The patch

  • removes the duplicated code regarding XPath and calls existing method OsmDataSessionImporter.extractFileName() instead
  • improves that method to first try to find a "file" node given the current element before falling back to the possibly very slow XPath evaluate call (not sure if the XPath part is still needed, it is never used in my example).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/session/NoteSessionImporter.java

    r18208 r18954  
    77import java.io.InputStream;
    88
    9 import javax.xml.xpath.XPath;
    10 import javax.xml.xpath.XPathConstants;
    11 import javax.xml.xpath.XPathExpression;
    12 import javax.xml.xpath.XPathExpressionException;
    13 import javax.xml.xpath.XPathFactory;
    14 
    159import org.openstreetmap.josm.gui.io.importexport.NoteImporter;
    1610import org.openstreetmap.josm.gui.layer.Layer;
     
    1913import org.openstreetmap.josm.io.IllegalDataException;
    2014import org.openstreetmap.josm.io.session.SessionReader.ImportSupport;
    21 import org.openstreetmap.josm.tools.Utils;
    2215import org.w3c.dom.Element;
    2316import org.xml.sax.SAXException;
     
    3528            throw new IllegalDataException(tr("Version ''{0}'' of meta data for note layer is not supported. Expected: 0.1", version));
    3629        }
    37         try {
    38             XPathFactory xPathFactory = XPathFactory.newInstance();
    39             XPath xpath = xPathFactory.newXPath();
    40             XPathExpression fileExp = xpath.compile("file/text()");
    41             String fileStr = (String) fileExp.evaluate(elem, XPathConstants.STRING);
    42             if (Utils.isEmpty(fileStr)) {
    43                 throw new IllegalDataException(tr("File name expected for layer no. {0}", support.getLayerIndex()));
    44             }
    4530
    46             NoteImporter importer = new NoteImporter();
    47             try (InputStream in = support.getInputStream(fileStr)) {
    48                 return importer.loadLayer(in, support.getFile(fileStr), support.getLayerName(), progressMonitor);
    49             }
    50         } catch (XPathExpressionException | SAXException e) {
     31        String fileStr = OsmDataSessionImporter.extractFileName(elem, support);
     32
     33        NoteImporter importer = new NoteImporter();
     34        try (InputStream in = support.getInputStream(fileStr)) {
     35            return importer.loadLayer(in, support.getFile(fileStr), support.getLayerName(), progressMonitor);
     36        } catch (SAXException e) {
    5137            throw new IllegalDataException(e);
    5238        }
Note: See TracChangeset for help on using the changeset viewer.