Skip to content

Commit 01cb9f8

Browse files
authored
Merge pull request #1928 from codeflash-ai/codeflash/optimize-Workload.repeatString-mndmishx
⚡️ Speed up method `Workload.repeatString` by 521%
2 parents f3eecac + 8cd2956 commit 01cb9f8

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

  • tests/test_languages/fixtures/java_tracer_e2e/src/main/java/com/example

tests/test_languages/fixtures/java_tracer_e2e/src/main/java/com/example/Workload.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ public static int computeSum(int n) {
1414
}
1515

1616
public static String repeatString(String s, int count) {
17-
String result = "";
18-
for (int i = 0; i < count; i++) {
19-
result = result + s;
17+
if (count <= 0) {
18+
return "";
2019
}
21-
return result;
20+
// Preserve original behavior where null becomes "null"
21+
String unit = String.valueOf(s);
22+
return unit.repeat(count);
2223
}
2324

2425
public static List<Integer> filterEvens(List<Integer> numbers) {

0 commit comments

Comments
 (0)