Skip to content

Commit

Permalink
8338543: ClassBuilder withMethod builders should cache the method typ…
Browse files Browse the repository at this point in the history
…e symbol
  • Loading branch information
liach committed Aug 19, 2024
1 parent 3ca359a commit 230caae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,7 @@ default ClassBuilder withMethodBody(String name,
MethodTypeDesc descriptor,
int methodFlags,
Consumer<? super CodeBuilder> handler) {
return withMethodBody(constantPool().utf8Entry(name),
constantPool().utf8Entry(descriptor),
methodFlags,
handler);
return withMethod(name, descriptor, methodFlags, mb -> mb.withCode(handler));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package jdk.internal.classfile.impl;

import java.lang.constant.MethodTypeDesc;
import java.util.function.Consumer;

import java.lang.classfile.*;
Expand Down Expand Up @@ -78,6 +79,15 @@ public ClassBuilder withMethod(Utf8Entry name, Utf8Entry descriptor, int flags,
return this;
}

@Override
public ClassBuilder withMethod(String name, MethodTypeDesc descriptor, int flags, Consumer<? super MethodBuilder> handler) {
var mb = new BufferedMethodBuilder(terminal.constantPool, terminal.context,
constantPool().utf8Entry(name), constantPool().utf8Entry(descriptor), flags, null);
mb.mDesc = descriptor;
consumer.accept(mb.run(handler).toModel());
return this;
}

@Override
public ClassBuilder transformMethod(MethodModel method, MethodTransform transform) {
BufferedMethodBuilder builder = new BufferedMethodBuilder(terminal.constantPool, terminal.context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package jdk.internal.classfile.impl;

import java.lang.constant.ConstantDescs;
import java.lang.constant.MethodTypeDesc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -106,6 +107,13 @@ public ClassBuilder withMethod(Utf8Entry name,
.run(handler));
}

@Override
public ClassBuilder withMethod(String name, MethodTypeDesc descriptor, int flags, Consumer<? super MethodBuilder> handler) {
var method = new DirectMethodBuilder(constantPool, context, constantPool.utf8Entry(name), constantPool.utf8Entry(descriptor), flags, null);
method.mDesc = descriptor;
return withMethod(method.run(handler));
}

@Override
public ClassBuilder transformMethod(MethodModel method, MethodTransform transform) {
DirectMethodBuilder builder = new DirectMethodBuilder(constantPool, context, method.methodName(),
Expand Down

0 comments on commit 230caae

Please sign in to comment.