Skip to content

Replace loop-based string concatenation with StringBuilder in path/polytree string rendering#26

Merged
micycle1 merged 2 commits intomasterfrom
copilot/optimize-string-concat-loop
Feb 15, 2026
Merged

Replace loop-based string concatenation with StringBuilder in path/polytree string rendering#26
micycle1 merged 2 commits intomasterfrom
copilot/optimize-string-concat-loop

Conversation

Copy link
Contributor

Copilot AI commented Feb 15, 2026

This change removes repeated String concatenation inside hot toString loops in core path and polytree types. The goal is to keep output identical while avoiding quadratic string-building behavior.

  • Core path string rendering

    • Updated toString() implementations in:
      • Path64
      • PathD
      • Paths64
      • PathsD
    • Replaced s = s + ... loop concatenation with StringBuilder.append(...).
  • Polytree string rendering

    • Updated PolyPathBase.toStringInternal(int idx, int level) and PolyPathBase.toString().
    • Replaced loop concatenation for:
      • indentation/padding construction
      • recursive child text aggregation
    • Preserved existing formatting, including line breaks and pluralization behavior.
  • Behavior-locking coverage

    • Added focused tests in TestToStringOutput to assert exact output strings for:
      • Path64
      • PathD
      • Paths64
      • PathsD
      • PolyPathBase (via PolyTree64)
// before
String s = "";
for (Point64 p : this) {
    s = s + p.toString() + " ";
}

// after
StringBuilder s = new StringBuilder();
for (Point64 p : this) {
    s.append(p.toString()).append(" ");
}
return s.toString();

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • jitpack.io
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/Clipper2-java/Clipper2-java org.codehaus.plexus.classworlds.launcher.Launcher test (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/Clipper2-java/Clipper2-java org.codehaus.plexus.classworlds.launcher.Launcher -Dtest=TestToStringOutput test (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/Clipper2-java/Clipper2-java org.codehaus.plexus.classworlds.launcher.Launcher -f pom.xml -B -V -e -Dfindbugs.skip -Dcheckstyle.skip -Dpmd.skip=true -Dspotbugs.skip -Denforcer.skip -Dmaven.javadoc.skip (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: micycle1 <9304234+micycle1@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor string concatenation to use StringBuilder in Path classes Replace loop-based string concatenation with StringBuilder in path/polytree string rendering Feb 15, 2026
Copilot AI requested a review from micycle1 February 15, 2026 23:07
@micycle1 micycle1 marked this pull request as ready for review February 15, 2026 23:08
@micycle1 micycle1 merged commit cef4ace into master Feb 15, 2026
1 check passed
@micycle1 micycle1 deleted the copilot/optimize-string-concat-loop branch February 15, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants