RFR: Minor fixes, microoptimizations and cleanup

Aleksey Shipilev shade at openjdk.java.net
Tue Oct 6 14:56:22 UTC 2020


On Wed, 30 Sep 2020 12:05:13 GMT, Sergey Ponomarev <github.com+415502+stokito at openjdk.org> wrote:

> I already signed Oracle contributor agreement and I'm JCP member so my changes can be accepted.

Thanks. It feels like some of these changes are unnecessary.

Looks fine, thanks. I'll integrate once bots clear the OCA mess.

jol-cli/src/main/java/org/openjdk/jol/OptionFormatter.java line 77:

> 75:         StringBuilder line = new StringBuilder(150);
> 76:
> 77:         StringBuilder o = new StringBuilder(32);

This is not performance-critical code, let's not over-optimize here.

jol-cli/src/main/java/org/openjdk/jol/OptionFormatter.java line 43:

> 41:
> 42:     public String format(Map<String, ? extends OptionDescriptor> options) {
> 43:         StringBuilder sb = new StringBuilder(400);

This is not performance-critical, let's not over-optimize.

jol-core/src/main/java/org/openjdk/jol/info/FieldLayout.java line 97:

> 95:     public String shortFieldName() {
> 96:         String classShortName = classShortName();
> 97:         return classShortName +  "." + name();

Inline `classShortName`?

jol-core/src/main/java/org/openjdk/jol/info/FieldLayout.java line 103:

> 101:         String cl = hostClass();
> 102:         int idx = cl.lastIndexOf(".");
> 103:         return idx != -1 && idx < cl.length() ? cl.substring(idx + 1) : cl;

Took me a while to recognize the ternary statement here. Should at least have parentheses?

 return (idx != -1 && idx < cl.length()) ? cl.substring(idx + 1) : cl;

Or maybe don't do this at all, and leave the if block:

if (idx != -1 && idx < cl.length()) {
  return cl.substring(idx + 1)
} else {
  return cl;
}

jol-samples/src/main/java/sun/misc/Contended.java line 40:

> 38: @Target(ElementType.FIELD)
> 39: @Retention(RetentionPolicy.RUNTIME)
> 40: public @interface Contended { String value() default "";

`value()` should be on new line?

jol-cli/src/main/java/org/openjdk/jol/operations/StringCompress.java line 97:

> 95:         }
> 96:
> 97:         List<Future<?>> res = new ArrayList<>(args.length);

This does not look performance-sensitive, let's not over-optimize.

-------------

Changes requested by shade (Committer).

PR: https://git.openjdk.java.net/jol/pull/3Marked as reviewed by shade (Committer).


More information about the jol-dev mailing list