Skip to content

Commit

Permalink
优化String.format
Browse files Browse the repository at this point in the history
  • Loading branch information
dongchenxu committed Sep 18, 2019
1 parent 5e2066d commit d600604
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
class SandboxClassLoader extends URLClassLoader {

private final String namespace;
private final String toString;
private final String path;

SandboxClassLoader(final String namespace,
final String sandboxCoreJarFilePath) throws MalformedURLException {
super(new URL[]{new URL("file:" + sandboxCoreJarFilePath)});
this.namespace = namespace;
this.path = sandboxCoreJarFilePath;
this.toString = String.format("SandboxClassLoader[namespace=%s;path=%s;]", namespace, path);
}

@Override
Expand Down Expand Up @@ -73,7 +73,7 @@ protected synchronized Class<?> loadClass(String name, boolean resolve) throws C

@Override
public String toString() {
return String.format("SandboxClassLoader[namespace=%s;path=%s;]", namespace, path);
return toString;
}


Expand Down Expand Up @@ -127,7 +127,7 @@ public void closeIfPossible() {
private <T> T forceGetDeclaredFieldValue(Class<?> clazz, String name, Object target) throws NoSuchFieldException, IllegalAccessException {
final Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
return (T)field.get(target);
return (T) field.get(target);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class CallAsmCodeLock extends AsmCodeLock {
*/
class AsmTryCatchBlock {

protected final Label start;
protected final Label end;
protected final Label handler;
protected final String type;
final Label start;
final Label end;
final Label handler;
final String type;

AsmTryCatchBlock(Label start, Label end, Label handler, String type) {
this.start = start;
Expand Down Expand Up @@ -111,18 +111,10 @@ private String getBehaviorSignCode(final String name,
final String desc) {
final Type methodType = Type.getMethodType(desc);
final Collection<String> parameterClassNameArray = new ArrayList<String>();
if (null != methodType.getArgumentTypes()) {
for (final Type parameterType : methodType.getArgumentTypes()) {
parameterClassNameArray.add(parameterType.getClassName());
}
for (final Type parameterType : methodType.getArgumentTypes()) {
parameterClassNameArray.add(parameterType.getClassName());
}
final String signCode = String.format(
"%s#%s(%s)",
targetJavaClassName,
name,
join(parameterClassNameArray, ",")
);
return signCode;
return targetJavaClassName + "#" + name + "(" + join(parameterClassNameArray, ",") + ")";
}

@Override
Expand Down

0 comments on commit d600604

Please sign in to comment.