Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace StringBuilder#append(String) with StringBuilder#append(char) #8008

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public CrashLog parse(String crashLog) {
pid = line.substring(pidIdx + 4, endIdx);
}
} else {
message.append(line.substring(2)).append("\n");
message.append(line.substring(2)).append('\n');
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public String evaluate(CapturedContext context, LogProbe.LogStatus status) {
status.addError(new EvaluationError(ex.getExpr(), ex.getMessage()));
String msg =
ex instanceof RedactedException ? Redaction.REDACTED_VALUE : ex.getMessage();
sb.append("{").append(msg).append("}");
sb.append('{').append(msg).append('}');
}
if (!status.getErrors().isEmpty()) {
status.setLogTemplateErrors(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String concatTags() {
StringBuilder sb = new StringBuilder();
for (Tag tag : tags) {
if (sb.length() > 0) {
sb.append(",");
sb.append(',');
}
sb.append(tag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static int buildPayloadBatch(
List<String> payloads, int start, int count, StringBuilder sb) {
int totalSize = 0;
int elementCount = 0;
sb.append("[");
sb.append('[');
for (int i = start; i < start + count; i++) {
String jsonStr = payloads.get(i);
totalSize += jsonStr.length();
Expand All @@ -71,13 +71,13 @@ private static int buildPayloadBatch(
break;
}
sb.append(jsonStr);
sb.append(",");
sb.append(',');
elementCount++;
}
if (elementCount > 0) {
sb.delete(sb.lastIndexOf(","), sb.length());
}
sb.append("]");
sb.append(']');
return elementCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public StringTokenWriter(StringBuilder sb, List<EvaluationError> evalErrors) {
@Override
public void prologue(Object value, String type) {
if (inMapEntry && !initial) {
sb.append("=");
sb.append('=');
} else if (inCollection && !initial) {
sb.append(", ");
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public void primitiveArrayElement(String value, String type) {

@Override
public void collectionPrologue(Object value) {
sb.append("[");
sb.append('[');
initial = true;
inCollection = true;
}
Expand All @@ -98,7 +98,7 @@ public void collectionEpilogue(Object value, boolean isComplete, int size) {

@Override
public void mapPrologue(Object value) {
sb.append("{");
sb.append('{');
initial = true;
inCollection = true;
}
Expand All @@ -108,14 +108,14 @@ public void mapEntryPrologue(Map.Entry<?, ?> entry) {
if (!initial) {
sb.append(", ");
}
sb.append("[");
sb.append('[');
initial = true;
inMapEntry = true;
}

@Override
public void mapEntryEpilogue(Map.Entry<?, ?> entry) {
sb.append("]");
sb.append(']');
inMapEntry = false;
}

Expand All @@ -127,7 +127,7 @@ public void mapEpilogue(boolean isComplete, int size) {

@Override
public void objectPrologue(Object value) {
sb.append("{");
sb.append('{');
initial = true;
}

Expand All @@ -137,12 +137,12 @@ public void objectFieldPrologue(String fieldName, Object value, int maxDepth) {
sb.append(", ");
}
initial = false;
sb.append(fieldName).append("=");
sb.append(fieldName).append('=');
}

@Override
public void objectEpilogue(Object value) {
sb.append("}");
sb.append('}');
}

@Override
Expand All @@ -167,16 +167,16 @@ public void notCaptured(SerializerWithLimits.NotCapturedReason reason) {
sb.append("...");
break;
case TIMEOUT:
sb.append("{").append(TIMEOUT_REASON).append("}");
sb.append('{').append(TIMEOUT_REASON).append('}');
break;
case FIELD_COUNT:
sb.append(", ...");
break;
case REDACTED_IDENT:
sb.append("{").append(REDACTED_IDENT_REASON).append("}");
sb.append('{').append(REDACTED_IDENT_REASON).append('}');
break;
case REDACTED_TYPE:
sb.append("{").append(REDACTED_TYPE_REASON).append("}");
sb.append('{').append(REDACTED_TYPE_REASON).append('}');
break;
default:
throw new RuntimeException("Unsupported NotCapturedReason: " + reason);
Expand All @@ -185,6 +185,6 @@ public void notCaptured(SerializerWithLimits.NotCapturedReason reason) {

@Override
public void notCaptured(String reason) throws Exception {
sb.append("(Error: ").append(reason).append(")");
sb.append("(Error: ").append(reason).append(')');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void splitDiagnosticsBatch() {
DebuggerSink sink = createDebuggerSink(diagnosticUploader, false);
StringBuilder largeMessageBuilder = new StringBuilder(100_001);
for (int i = 0; i < 100_000; i++) {
largeMessageBuilder.append("f");
largeMessageBuilder.append('f');
}
String largeMessage = largeMessageBuilder.toString();
for (int i = 0; i < 100; i++) {
Expand All @@ -342,7 +342,7 @@ public void splitDiagnosticsBatchDebuggerTrack() {
DebuggerSink sink = createDebuggerSink(diagnosticUploader, true);
StringBuilder largeMessageBuilder = new StringBuilder(100_001);
for (int i = 0; i < 100_000; i++) {
largeMessageBuilder.append("f");
largeMessageBuilder.append('f');
}
String largeMessage = largeMessageBuilder.toString();
for (int i = 0; i < 100; i++) {
Expand All @@ -362,7 +362,7 @@ public void tooLargeDiagnostic() {
DebuggerSink sink = createDefaultDebuggerSink();
StringBuilder tooLargeMessageBuilder = new StringBuilder(MAX_PAYLOAD + 1);
for (int i = 0; i < MAX_PAYLOAD; i++) {
tooLargeMessageBuilder.append("f");
tooLargeMessageBuilder.append('f');
}
String tooLargeMessage = tooLargeMessageBuilder.toString();
sink.getProbeDiagnosticsSink().addError(new ProbeId("1", 1), tooLargeMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void collection() throws IOException {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10; i++) {
if (i > 0) {
sb.append(",");
sb.append(',');
}
sb.append(String.format(CAPTURED_VALUE_SIMPLE_TEMPLATE, int.class.getTypeName(), i));
}
Expand All @@ -66,7 +66,7 @@ void collection() throws IOException {
sb = new StringBuilder();
for (int i = 0; i < 10; i++) {
if (i > 0) {
sb.append(",");
sb.append(',');
}
sb.append(
String.format(CAPTURED_VALUE_SIMPLE_TEMPLATE, String.class.getTypeName(), "foo" + i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ private void embedException(StringBuilder buf, Throwable t) {
if (t != null) {
buf.append(" [exception:");
buf.append(t.toString());
buf.append(".");
buf.append('.');
for (StackTraceElement element : t.getStackTrace()) {
buf.append(" at ");
buf.append(element.toString());
}
buf.append("]");
buf.append(']');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ public void dispatch(List<Map<String, Object>> messages) {
}

if (batchCount + 1 > maxBatchRecords || batchLength + bytes.length >= maxBatchBytes) {
flush(batch.append("]"));
flush(batch.append(']'));
batch = new StringBuilder("[");
batchCount = 0;
batchLength = 0;
}

if (batchCount != 0) {
batch.append(",");
batch.append(',');
}
batch.append(json);
batchCount += 1;
batchLength += bytes.length;
}

flush(batch.append("]"));
flush(batch.append(']'));
}

private void flush(StringBuilder batch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ String cmdStartProfiling(Path file) throws IllegalStateException {
// wall profiling is enabled.
cmd.append(",wall=");
if (getWallCollapsing(configProvider)) {
cmd.append("~");
cmd.append('~');
}
cmd.append(getWallInterval(configProvider)).append('m');
if (getWallContextFilter(configProvider)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private static void summarize(StringBuilder buf, String prefix, AtomicLong stat)
long value = stat.get();
buf.append(prefix)
.append(String.format("%-12d", value >>> COUNT_SHIFT))
.append(" ")
.append(' ')
.append(String.format("%.1f", (value & NANOS_MASK) / 1_000_000.0))
.append(" ms\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,26 @@ private static String prettyPrint(final String prefix, final Reference ref) {
builder.append(Reference.prettyPrint(ref.flags));
builder.append(ref.className);
if (ref.superName != null) {
builder.append(" extends<").append(ref.superName).append(">");
builder.append(" extends<").append(ref.superName).append('>');
}
if (ref.interfaces.length > 0) {
builder.append(" implements ");
for (final String iface : ref.interfaces) {
builder.append(" <").append(iface).append(">");
builder.append(" <").append(iface).append('>');
}
}
for (final String source : ref.sources) {
builder.append("\n").append(prefix).append(prefix);
builder.append('\n').append(prefix).append(prefix);
builder.append("Source: ").append(source);
}
for (final Reference.Field field : ref.fields) {
builder.append("\n").append(prefix).append(prefix);
builder.append('\n').append(prefix).append(prefix);
builder.append("Field: ");
builder.append(Reference.prettyPrint(field.flags));
builder.append(field);
}
for (final Reference.Method method : ref.methods) {
builder.append("\n").append(prefix).append(prefix);
builder.append('\n').append(prefix).append(prefix);
builder.append("Method: ");
builder.append(Reference.prettyPrint(method.flags));
builder.append(method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public SdkRequest modifyRequest(
}

detailBuilder
.append("\"")
.append('\"')
.append(PathwayContext.DATADOG_KEY)
.append("\": ")
.append(traceContext)
Expand Down Expand Up @@ -104,7 +104,7 @@ private String getTraceContextToInject(
.append(RESOURCE_NAME_KEY)
.append("\": \"")
.append(eventBusName)
.append("\"");
.append('\"');

jsonBuilder.append('}');
return jsonBuilder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ private ByteBuffer getMessageAttributeValueToInject(
AmazonWebServiceRequest request, String snsTopicName) {
final AgentSpan span = newSpan(request);
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.append("{");
jsonBuilder.append('{');
propagate().inject(span, jsonBuilder, SETTER, TracePropagationStyle.DATADOG);
if (traceConfig().isDataStreamsEnabled()) {
propagate().injectPathwayContext(span, jsonBuilder, SETTER, getTags(snsTopicName));
}
jsonBuilder.setLength(jsonBuilder.length() - 1); // Remove the last comma
jsonBuilder.append("}");
jsonBuilder.append('}');
return ByteBuffer.wrap(jsonBuilder.toString().getBytes(StandardCharsets.UTF_8));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class TextMapInjectAdapter implements AgentPropagation.Setter<StringBuild

@Override
public void set(final StringBuilder builder, final String key, final String value) {
builder.append("\"").append(key).append("\":\"").append(value).append("\",");
builder.append('\"').append(key).append("\":\"").append(value).append("\",");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ private SdkBytes getMessageAttributeValueToInject(
ExecutionAttributes executionAttributes, String snsTopicName) {
final AgentSpan span = executionAttributes.getAttribute(SPAN_ATTRIBUTE);
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.append("{");
jsonBuilder.append('{');
propagate().inject(span, jsonBuilder, SETTER);
if (traceConfig().isDataStreamsEnabled()) {
propagate().injectPathwayContext(span, jsonBuilder, SETTER, getTags(snsTopicName));
}
jsonBuilder.setLength(jsonBuilder.length() - 1); // Remove the last comma
jsonBuilder.append("}");
jsonBuilder.append('}');
return SdkBytes.fromString(jsonBuilder.toString(), StandardCharsets.UTF_8);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class TextMapInjectAdapter implements AgentPropagation.Setter<StringBuild

@Override
public void set(final StringBuilder builder, final String key, final String value) {
builder.append("\"").append(key).append("\":\"").append(value).append("\",");
builder.append('\"').append(key).append("\":\"").append(value).append("\",");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private String buildRoutePath(final Path classPath, final Path methodPath) {
boolean skipSlash = false;
if (classPath != null) {
if (!classPath.value().startsWith("/")) {
route.append("/");
route.append('/');
}
route.append(classPath.value());
skipSlash = classPath.value().endsWith("/");
Expand All @@ -192,7 +192,7 @@ private String buildRoutePath(final Path classPath, final Path methodPath) {
path = path.length() == 1 ? "" : path.substring(1);
}
} else if (!path.startsWith("/")) {
route.append("/");
route.append('/');
}
route.append(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private String buildRoutePath(final Path classPath, final Path methodPath) {
boolean skipSlash = false;
if (classPath != null) {
if (!classPath.value().startsWith("/")) {
route.append("/");
route.append('/');
}
route.append(classPath.value());
skipSlash = classPath.value().endsWith("/");
Expand All @@ -183,7 +183,7 @@ private String buildRoutePath(final Path classPath, final Path methodPath) {
path = path.length() == 1 ? "" : path.substring(1);
}
} else if (!path.startsWith("/")) {
route.append("/");
route.append('/');
}
route.append(path);
}
Expand Down
Loading
Loading