From fc00ec8702793c5899b9f5653eb778fd1f8f1d98 Mon Sep 17 00:00:00 2001 From: Andrew Dinn Date: Wed, 12 Jul 2023 15:55:30 +0100 Subject: [PATCH] Pre-populate class entry file and dir lists at create --- .../objectfile/debugentry/ClassEntry.java | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/ClassEntry.java b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/ClassEntry.java index f81014699c9ea..703abc5eccdb6 100644 --- a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/ClassEntry.java +++ b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/ClassEntry.java @@ -90,12 +90,12 @@ public class ClassEntry extends StructureTypeEntry { * A list of all files referenced from info associated with this class, including info detailing * inline method ranges. */ - private ArrayList files; + final private ArrayList files; /** * A list of all directories referenced from info associated with this class, including info * detailing inline method ranges. */ - private ArrayList dirs; + final private ArrayList dirs; /** * An index identifying the file table position of every file referenced from info associated * with this class, including info detailing inline method ranges. @@ -113,8 +113,9 @@ public ClassEntry(String className, FileEntry fileEntry, int size) { this.loader = null; // file and dir lists/indexes are populated after all DebugInfo API input has // been received and are only created on demand - files = null; - dirs = null; + files = new ArrayList<>(); + dirs = new ArrayList<>(); + // create these on demand using the size of the file and dir lists this.fileIndex = null; this.dirIndex = null; } @@ -375,9 +376,6 @@ public int hipc() { * @param file The file to be added. */ public void includeFile(FileEntry file) { - if (files == null) { - files = new ArrayList<>(); - } assert !files.contains(file) : "caller should ensure file is only included once"; assert fileIndex == null : "cannot include files after index has been created"; files.add(file); @@ -389,9 +387,6 @@ public void includeFile(FileEntry file) { * @param dirEntry The directory to be added. */ public void includeDir(DirEntry dirEntry) { - if (dirs == null) { - dirs = new ArrayList<>(); - } assert !dirs.contains(dirEntry) : "caller should ensure dir is only included once"; assert dirIndex == null : "cannot include dirs after index has been created"; dirs.add(dirEntry); @@ -404,18 +399,14 @@ public void includeDir(DirEntry dirEntry) { public void buildFileAndDirIndexes() { // this is a one-off operation assert fileIndex == null && dirIndex == null : "file and indexes can only be generated once"; - if (files == null) { - assert dirs == null : "should not have included any dirs if we have no files"; - return; + if (files.isEmpty()) { + assert dirs.isEmpty() : "should not have included any dirs if we have no files"; } int idx = 1; fileIndex = EconomicMap.create(files.size()); for (FileEntry file : files) { fileIndex.put(file, idx++); } - if (dirs == null) { - return; - } dirIndex = EconomicMap.create(dirs.size()); idx = 1; for (DirEntry dir : dirs) { @@ -434,7 +425,7 @@ public void buildFileAndDirIndexes() { * @return a stream of all referenced files */ public Stream fileStream() { - if (files != null) { + if (!files.isEmpty()) { return files.stream(); } else { return Stream.empty(); @@ -448,7 +439,7 @@ public Stream fileStream() { * @return a stream of all referenced directories */ public Stream dirStream() { - if (dirs != null) { + if (!dirs.isEmpty()) { return dirs.stream(); } else { return Stream.empty();