Skip to content

Conversation

@mernst
Copy link
Member

@mernst mernst commented Sep 12, 2025

Summary by CodeRabbit

  • Refactor

    • Standardized many index/lastIndex checks to use character-based lookups for minor performance/memory improvements; no behavioral changes.
  • Style

    • Unified literal usage across parsing, formatting, and instrumentation for consistent code style.
  • Tests

    • Updated test helpers to align with internal refactors without altering test behavior.

@coderabbitai
Copy link

coderabbitai bot commented Sep 12, 2025

📝 Walkthrough

Walkthrough

System-wide replacements of single-character String arguments in indexOf/lastIndexOf calls with equivalent char-literal overloads across multiple Java files. No API, control-flow, or behavioral changes introduced.

Changes

Cohort / File(s) Summary of changes
Argument stringification
java/daikon/Chicory.java, java/daikon/DynComp.java
Use char overload for space checks (" " -> ' ') in args stringification.
Debug parsing
java/daikon/Debug.java
Switch def.indexOf("@") -> def.indexOf('@') in add_track.
Invariant / var name parsing
java/daikon/PrintInvariants.java, java/daikon/VarComparabilityImplicit.java, java/daikon/VarInfo.java, java/daikon/VarInfoName.java
Replace string-literal indexOf/lastIndexOf calls for brackets/parentheses/tilde with char overloads (e.g., "["->'[', ")"->')', "~"->'~').
Chicory instrumentation
java/daikon/chicory/Instrument.java, java/daikon/chicory/Instrument24.java
Use lastIndexOf('$') instead of lastIndexOf("$") to locate inner-class separators.
dcomp runtime / tagging
java/daikon/dcomp/DCRuntime.java, java/daikon/dcomp/TagEntry.java
Use lastIndexOf('.') char overload for package/class abbreviation logic.
Diff visitors
java/daikon/diff/MatchCountVisitor.java, java/daikon/diff/MultiDiffVisitor.java
Use char overload for decimal-point detection ("."->'.'); one commented condition updated from ">" to '>'.
Tools (general)
java/daikon/tools/ExtractConsequent.java, java/daikon/tools/compare/LogicalCompare.java
Switch to char overloads for '(' and '#' detection; LogicalCompare uses a local hash variable to split formula/comment.
Tools (JTB)
java/daikon/tools/jtb/CreateSpinfo.java, java/daikon/tools/jtb/CreateSpinfoC.java
Replace indexOf/lastIndexOf of "." with char '.' overloads in filename handling.
Runtime checker
java/daikon/tools/runtimechecker/InstrumentVisitor.java
Use char overloads for '"' and '\\' checks in toProperty ("\""->'\"', "\\")->'\\').
Tests
java/daikon/test/inv/InvariantAddAndCheckTester.java
Replace indexOf(":") with indexOf(':') for command parsing.

Sequence Diagram(s)

(omitted — changes are local overload substitutions with no control-flow or interaction changes)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Make call to indexOf() more efficient" is a short, single-sentence summary that accurately reflects the main change in the diff (replacing string-literal indexOf calls with char-literal overloads for micro-optimization) and is clear enough for a reviewer to understand the primary intent.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0a97f0 and 1104da1.

📒 Files selected for processing (1)
  • java/daikon/tools/ExtractConsequent.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: codespecs.daikon (kvasir_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (typecheck_latest_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (misc_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (typecheck_bundled_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (nontxt_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (quick_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (nonquick_ubuntu_jdk24)
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (9)
java/daikon/Chicory.java (1)

644-649: Char overload is fine; quoting logic is incorrect (wraps the whole string, not the arg)

Current code quotes the accumulated str when an arg has spaces, rather than quoting that arg. Suggest fixing to quote just the arg.

-    for (String arg : args) {
-      if (arg.indexOf(' ') != -1) {
-        str = "'" + str + "'";
-      }
-      str += arg + " ";
-    }
+    for (String arg : args) {
+      if (arg.indexOf(' ') != -1) {
+        str += "'" + arg + "' ";
+      } else {
+        str += arg + " ";
+      }
+    }
java/daikon/tools/ExtractConsequent.java (1)

425-427: Off-by-one when trimming trailing '.'

Should remove 1 char, not 2.

-    if (pptname.endsWith(".")) {
-      pptname = pptname.substring(0, pptname.length() - 2);
-    }
+    if (pptname.endsWith(".")) {
+      pptname = pptname.substring(0, pptname.length() - 1);
+    }
java/daikon/tools/jtb/CreateSpinfo.java (2)

156-158: User-facing message missing a space

Add a space before “does”.

-    System.err.println(
-        "Warning: CreateSpinfo input file " + javaFileName + "does not end in .java.");
+    System.err.println(
+        "Warning: CreateSpinfo input file " + javaFileName + " does not end in .java.");

160-165: Consider using lastIndexOf for multi-dot filenames

Using the last dot better models “change the extension” (e.g., foo.bar → foo.spinfo).

-    int dotPos = javaFileName.indexOf('.');
+    int dotPos = javaFileName.lastIndexOf('.');
java/daikon/dcomp/DCRuntime.java (1)

2919-2924: Default toString comparison uses decimal hash; should be hex

java.lang.Object.toString uses hex identity hash; current check will rarely match.

-      String default_tostring =
-          String.format("%s@%s", obj.getClass().getName(), System.identityHashCode(obj));
+      String default_tostring =
+          obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj));
java/daikon/DynComp.java (1)

418-426: Use StringBuilder for argsToString

Avoids quadratic string concatenation.

-  public String argsToString(List<String> args) {
-    String str = "";
-    for (String arg : args) {
-      if (arg.indexOf(' ') != -1) {
-        arg = "'" + arg + "'";
-      }
-      str += arg + " ";
-    }
-    return str.trim();
-  }
+  public String argsToString(List<String> args) {
+    StringBuilder sb = new StringBuilder();
+    for (String arg : args) {
+      if (arg.indexOf(' ') >= 0) {
+        arg = "'" + arg + "'";
+      }
+      sb.append(arg).append(' ');
+    }
+    if (sb.length() == 0) return "";
+    sb.setLength(sb.length() - 1); // drop trailing space
+    return sb.toString();
+  }
java/daikon/VarInfoName.java (3)

742-744: Fix off-by-one when stripping "..." wrapper

substring end index should be length()-1 to drop only the trailing '~'. Current code drops two chars.

Apply this diff:

-        s = s.substring(1, s.length() - 2) + ":closure";
+        s = s.substring(1, s.length() - 1) + ":closure";

1311-1313: Union incorrectly labeled as "intersection"

Likely copy/paste: the Union constructor passes "intersection" to super, producing wrong names.

Apply this diff:

-      super("intersection", Arrays.asList(seq1, seq2));
+      super("union", Arrays.asList(seq1, seq2));

1456-1456: Avoid regex for literal replacement

replaceAll compiles a regex; replace is cheaper and clearer for removing "[]".

Apply this diff:

-      String term_name_no_brackets = term.name().replaceAll("\\[\\]", "") + "." + field;
+      String term_name_no_brackets = term.name().replace("[]", "") + "." + field;
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1f6cf0 and 84e601d.

📒 Files selected for processing (19)
  • java/daikon/Chicory.java (1 hunks)
  • java/daikon/Debug.java (1 hunks)
  • java/daikon/DynComp.java (1 hunks)
  • java/daikon/PrintInvariants.java (1 hunks)
  • java/daikon/VarComparabilityImplicit.java (1 hunks)
  • java/daikon/VarInfo.java (2 hunks)
  • java/daikon/VarInfoName.java (2 hunks)
  • java/daikon/chicory/Instrument.java (1 hunks)
  • java/daikon/chicory/Instrument24.java (1 hunks)
  • java/daikon/dcomp/DCRuntime.java (1 hunks)
  • java/daikon/dcomp/TagEntry.java (1 hunks)
  • java/daikon/diff/MatchCountVisitor.java (1 hunks)
  • java/daikon/diff/MultiDiffVisitor.java (1 hunks)
  • java/daikon/test/inv/InvariantAddAndCheckTester.java (2 hunks)
  • java/daikon/tools/ExtractConsequent.java (1 hunks)
  • java/daikon/tools/compare/LogicalCompare.java (1 hunks)
  • java/daikon/tools/jtb/CreateSpinfo.java (1 hunks)
  • java/daikon/tools/jtb/CreateSpinfoC.java (1 hunks)
  • java/daikon/tools/runtimechecker/InstrumentVisitor.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: codespecs.daikon (typecheck_latest_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (misc_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (kvasir_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (typecheck_bundled_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (quick_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (nontxt_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (nonquick_ubuntu_jdk24)
🔇 Additional comments (16)
java/daikon/diff/MultiDiffVisitor.java (1)

251-253: No-op change in comment only — safe to merge

Switching ">" to '>' inside a commented-out condition has no runtime effect.

java/daikon/Chicory.java (1)

645-645: Use of indexOf(char) is appropriate here

Behavior unchanged and avoids needless String allocation.

java/daikon/chicory/Instrument24.java (1)

1376-1384: Char overload for lastIndexOf is correct and slightly faster

No semantic change; good consistency with the PR goal.

java/daikon/VarComparabilityImplicit.java (1)

101-105: Char overload in lastIndexOf is correct

No behavior change; good.

java/daikon/diff/MatchCountVisitor.java (1)

181-186: Char overload for decimal point check looks good

Keeps semantics; minor perf win.

java/daikon/tools/ExtractConsequent.java (1)

421-423: Char overload change: LGTM

Semantics unchanged; minor allocation win.

java/daikon/tools/jtb/CreateSpinfo.java (1)

160-165: Char overload change: LGTM

No behavior change.

java/daikon/dcomp/DCRuntime.java (1)

2202-2204: Char overload change: LGTM

Matches intent, avoids creating a String.

java/daikon/DynComp.java (1)

421-423: Char overload change: LGTM

No functional change.

java/daikon/test/inv/InvariantAddAndCheckTester.java (1)

451-452: Char overload changes: LGTM

Keeps behavior; avoids constructing temporary Strings.

Also applies to: 499-500

java/daikon/chicory/Instrument.java (1)

1157-1163: Char overload change: LGTM

No semantic changes.

java/daikon/tools/runtimechecker/InstrumentVisitor.java (1)

1079-1097: Char overload changes: LGTM

Equivalent logic; slightly faster.

java/daikon/VarInfo.java (1)

1114-1115: Char overload change is correct.

Switching to indexOf('~') avoids a one-char String allocation; semantics unchanged.

java/daikon/Debug.java (1)

841-841: Char overload change is correct.

indexOf('@') is a no-op semantic change and removes a tiny allocation.

java/daikon/VarInfoName.java (2)

130-130: Char overload switch is correct

Using lastIndexOf('[') is semantically identical here and marginally faster. LGTM.


1734-1734: Comment-only edits are fine

Switching to lastIndexOf(')') in commented snippets is consistent with the PR’s goal; no runtime impact.

Also applies to: 1742-1742

mernst and others added 3 commits September 11, 2025 23:19
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16e871e and f0a97f0.

📒 Files selected for processing (1)
  • java/daikon/tools/ExtractConsequent.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: codespecs.daikon (kvasir_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (typecheck_bundled_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (typecheck_latest_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (misc_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (quick_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (nontxt_ubuntu_jdk24)
  • GitHub Check: codespecs.daikon (nonquick_ubuntu_jdk24)
🔇 Additional comments (1)
java/daikon/tools/ExtractConsequent.java (1)

426-426: Good micro-optimization: use char overload for indexOf.

Switching to indexOf('(') avoids constructing a temporary String. LGTM.

@mernst mernst merged commit 3c3b166 into codespecs:master Sep 12, 2025
70 checks passed
@mernst mernst deleted the indexof-singleton-string branch September 12, 2025 15:29
@coderabbitai coderabbitai bot mentioned this pull request Sep 17, 2025
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.

1 participant