Skip to content

Commit

Permalink
Performance optimization: cache method specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jwharm committed Aug 3, 2023
1 parent 18176f5 commit 578f4f8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/bld/java/io/github/jwharm/javagi/model/Method.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class Method extends GirElement implements CallableType {
public String visibility = "public";
public boolean skip = false;

private String methodSpecification = null;

public Method(GirElement parent, String name, String cIdentifier, String deprecated,
String throws_, String shadowedBy, String shadows, String movedTo) {
super(parent);
Expand Down Expand Up @@ -106,6 +108,10 @@ public String getMethodDeclaration() {
}

public String getMethodSpecification() {
if (this.methodSpecification != null) {
return this.methodSpecification;
}

SourceWriter writer = new SourceWriter(new StringWriter());

try {
Expand All @@ -130,7 +136,9 @@ public String getMethodSpecification() {
// StringWriter will never throw IOException
}

return writer.toString();
// Cache the result for future invocations
this.methodSpecification = writer.toString();
return this.methodSpecification;
}

public void generate(SourceWriter writer) throws IOException {
Expand Down

0 comments on commit 578f4f8

Please sign in to comment.