From 5a22c94b29aa3cbc998ca0f28f2218ad1890b212 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Sun, 22 May 2022 18:36:36 +0200 Subject: [PATCH] Detect also marked as needed methods if the method was previous add as replacement --- .../jwebassembly/module/FunctionManager.java | 9 ++++++--- .../jwebassembly/module/ModuleGenerator.java | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/module/FunctionManager.java b/src/de/inetsoftware/jwebassembly/module/FunctionManager.java index 0f9b6e40..6823a2b7 100644 --- a/src/de/inetsoftware/jwebassembly/module/FunctionManager.java +++ b/src/de/inetsoftware/jwebassembly/module/FunctionManager.java @@ -45,6 +45,8 @@ class FunctionManager { private final Set usedClasses = new LinkedHashSet<>(); + private int neededCount; + private boolean isFinish; /** @@ -71,12 +73,12 @@ private FunctionState getOrCreate( @Nonnull FunctionName name ) { } /** - * Get the count of known functions + * Get the count of needed functions * * @return the count */ - int size() { - return states.size(); + int getNeededCount() { + return neededCount; } /** @@ -171,6 +173,7 @@ FunctionName markAsNeeded( @Nonnull FunctionName name, boolean needThisParameter if( isFinish ) { throw new WasmException( "Prepare was already finish: " + name.signatureName, -1 ); } + neededCount++; state.state = State.Needed; state.needThisParameter = needThisParameter; JWebAssembly.LOGGER.fine( "\t\tcall: " + name.signatureName ); diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java index 9865bdb5..f3051df9 100644 --- a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java +++ b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java @@ -327,10 +327,10 @@ public void prepareFinish() throws IOException { int functCount; do { scanFunctions(); - functCount = functions.size(); // scan the functions can find new needed types or only new needed fields in the known types + functCount = functions.getNeededCount(); // scan the functions can find new needed types or only new needed fields in the known types scanForClinit(); types.scanTypeHierarchy(); // scan the type hierarchy can find new functions - } while( functCount < functions.size() ); + } while( functCount < functions.getNeededCount() ); // write only the needed imports to the output for( Iterator iterator = functions.getNeededImports(); iterator.hasNext(); ) {