Skip to content

Commit

Permalink
Pre-populate class entry file and dir lists at create
Browse files Browse the repository at this point in the history
  • Loading branch information
adinn committed Jul 12, 2023
1 parent 8e4c43c commit fc00ec8
Showing 1 changed file with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileEntry> files;
final private ArrayList<FileEntry> files;
/**
* A list of all directories referenced from info associated with this class, including info
* detailing inline method ranges.
*/
private ArrayList<DirEntry> dirs;
final private ArrayList<DirEntry> dirs;
/**
* An index identifying the file table position of every file referenced from info associated
* with this class, including info detailing inline method ranges.
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -434,7 +425,7 @@ public void buildFileAndDirIndexes() {
* @return a stream of all referenced files
*/
public Stream<FileEntry> fileStream() {
if (files != null) {
if (!files.isEmpty()) {
return files.stream();
} else {
return Stream.empty();
Expand All @@ -448,7 +439,7 @@ public Stream<FileEntry> fileStream() {
* @return a stream of all referenced directories
*/
public Stream<DirEntry> dirStream() {
if (dirs != null) {
if (!dirs.isEmpty()) {
return dirs.stream();
} else {
return Stream.empty();
Expand Down

0 comments on commit fc00ec8

Please sign in to comment.