rspec/rules/S3009/java/rule.adoc

48 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
It's slightly more efficient to append single characters to ``++StringBuffer++`` and ``++StringBuilder++`` instances as ``++char++``s, than as ``++String++``s. That is, it's more efficient to put a single ``++char++`` in single quotes, rather than double quotes.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
StringBuilder sb = new StringBuilder();
sb.append("a"); // Noncompliant
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
StringBuilder sb = new StringBuilder();
sb.append('a'); // Noncompliant
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Use single quotes around 'x'.
'''
== Comments And Links
(visible only on this page)
=== on 16 Jun 2015, 17:03:28 Nicolas Peru wrote:
I really doubt this one should be activated by default. This is really something that you should activate either, to be anal on your style or because you have a perf critical application that actually cares about this, so any way I would not include it in default profile.
=== on 16 Jun 2015, 17:16:31 Ann Campbell wrote:
done [~nicolas.peru]
endif::env-github,rspecator-view[]