-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Martin,

On 7/6/20 03:09, [email protected] wrote:
> diff --git
> a/java/org/apache/catalina/connector/CoyotePrincipal.java
> b/java/org/apache/catalina/connector/CoyotePrincipal.java index
> 1ae5608..93d7c02 100644 ---
> a/java/org/apache/catalina/connector/CoyotePrincipal.java +++
> b/java/org/apache/catalina/connector/CoyotePrincipal.java @@ -64,7
> +64,7 @@ public class CoyotePrincipal implements Principal,
> Serializable { public String toString() { StringBuilder sb = new
> StringBuilder("CoyotePrincipal["); sb.append(this.name); -
> sb.append("]"); +        sb.append(']'); return sb.toString(); }

Might I suggest further improvements?

Step 1:

      public String toString() {
          return new StringBuilder("CoyotePrincipal[")
          .append(this.name);
          .append(']');
          .toString();

It turns out that the generated bytecode is something like 2/3 as long
as the sb.append(); sb.append(); sb.append(); code. JIT probably does
the same thing eventually, but why not help it out?

Step 2:

      public String toString() {
          return "CoyotePrincipal[" + this.name + ']';
      }

This has a few advantages:

1. It's dead easy to read

2. The compiler makes the best decision as to how to perform the
concatenation

In very old versions of Java, you'll get StringBuffer concatenation as
the pre-commit version. Later versions get you StringBuilder as
post-commit version. Post 9.x-versions get you a call to
StringConcatFactory.makeConcatWithConstants which is presumably even
more efficient.

I understand that this was supposed to be a small patch, but I think
further improvements are possible in many cases like this one.

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl8DMT8ACgkQHPApP6U8
pFgUtA/+OoHnIgHBLoIOXqP5t10g/dBFxGrIpOUOe1MvIhWMdObcNIlZmnM1vv0Z
xCRYXxGCj20xm4P/NEzvRlEPWfd0uvoZczr34JVPlgOWUBJeRHmLQ+KlGdCeuuKk
cmxV4ZXZSt8bzVMufQ+N2RPOCGUvti2kin0CSj9BlygKuTAMuXgwVcyEo7XvLf3z
153dHylBL3ka5jo2lR4vYlj8U6PvzoZuLj3NAnrRZP3YttbQKimhXDcOg7zkeVP+
GFINDBE+fux+s5P38vqRLqzA4JEDFfjsKzT4JV21BrSbxhdUbXyYE4RMhW+izKB8
B/SJhBtEN1huED3GkZbg/DN0nYgY4vVeoHz4kdal1E5uVybG5SLj6xoz6tkRsayB
pOHguW1ds8NLPJwHBEATq6YQOXGfqECbW+iWuP54F7eBzo57CiZWsnQPalpSo9pn
mdBRbcfyI7z9vJFaiGCpudKGKK5+F1VFj6KELxZP7nAO0Lyhwapsai9TzLXLOTk1
8ReS5GENoZDrzrb3Gn/YCmdYAxdED9ejjkiY5qVjX3ZXWXaeytcz1h3bY2opV4Ks
a+tahArWqI1t44cemejJuiXFZB0xrDjji6pnd3ZqZ4vG1TREKxK2hdLjuwP3vaw9
fqt4d3E596rPtqF2e0aJLGfW+3iJ2r67c7DP9ARHMAdadMIi23U=
=N+0c
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to