Ignore:
Timestamp:
2021-03-16T21:56:57+01:00 (3 years ago)
Author:
simon04
Message:

fix #20563 - PluginListParser.parse amounts to 80% of allocations during startup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r16874 r17571  
    1919import java.util.Map;
    2020import java.util.Optional;
    21 import java.util.TreeMap;
    2221import java.util.jar.Attributes;
    2322import java.util.jar.JarInputStream;
     
    9493    public List<URL> libraries = new LinkedList<>();
    9594    /** All manifest attributes. */
    96     public final Map<String, String> attr = new TreeMap<>();
     95    public Attributes attr;
    9796    /** Invalid manifest entries */
    9897    final List<String> invalidManifestEntries = new ArrayList<>();
     
    134133            if (manifest == null)
    135134                throw new PluginException(tr("The plugin file ''{0}'' does not include a Manifest.", file.toString()));
    136             scanManifest(manifest, false);
     135            scanManifest(manifest.getMainAttributes(), false);
    137136            libraries.add(0, Utils.fileToURL(file));
    138137        } catch (IOException | InvalidPathException e) {
     
    151150     */
    152151    public PluginInformation(InputStream manifestStream, String name, String url) throws PluginException {
    153         this.name = name;
    154152        try {
    155153            Manifest manifest = new Manifest();
     
    158156                downloadlink = url;
    159157            }
    160             scanManifest(manifest, url != null);
     158            scanManifest(manifest.getMainAttributes(), url != null);
    161159        } catch (IOException e) {
    162160            throw new PluginException(name, e);
    163161        }
     162    }
     163
     164    /**
     165     * Creates a plugin information object by reading plugin information in Manifest format
     166     * from the input stream {@code manifestStream}.
     167     *
     168     * @param attr the manifest attributes
     169     * @param name the plugin name
     170     * @param url the download URL for the plugin
     171     * @throws PluginException if the plugin information can't be read from the input stream
     172     */
     173    public PluginInformation(Attributes attr, String name, String url) throws PluginException {
     174        this.name = name;
     175        if (url != null) {
     176            downloadlink = url;
     177        }
     178        scanManifest(attr, url != null);
    164179    }
    165180
     
    189204        this.canloadatruntime = other.canloadatruntime;
    190205        this.libraries = other.libraries;
    191         this.attr.clear();
    192         this.attr.putAll(other.attr);
     206        this.attr = new Attributes(other.attr);
    193207        this.invalidManifestEntries.clear();
    194208        this.invalidManifestEntries.addAll(other.invalidManifestEntries);
     
    215229    }
    216230
    217     private void scanManifest(Manifest manifest, boolean oldcheck) {
     231    private void scanManifest(Attributes attr, boolean oldcheck) {
    218232        String lang = LanguageInfo.getLanguageCodeManifest();
    219         Attributes attr = manifest.getMainAttributes();
    220233        className = attr.getValue("Plugin-Class");
    221234        String s = Optional.ofNullable(attr.getValue(lang+"Plugin-Link")).orElseGet(() -> attr.getValue("Plugin-Link"));
     
    318331            }
    319332        }
    320         for (Object o : attr.keySet()) {
    321             this.attr.put(o.toString(), attr.getValue(o.toString()));
    322         }
     333        this.attr = attr;
    323334    }
    324335
Note: See TracChangeset for help on using the changeset viewer.