Skip to content

Add public Slice.indexOfByte with offset and length and Slice.indexOfAnyByte - #195

Merged
dain merged 2 commits into
airlift:masterfrom
wendigo:user/serafin/index-of-byte
Jul 14, 2026
Merged

Add public Slice.indexOfByte with offset and length and Slice.indexOfAnyByte#195
dain merged 2 commits into
airlift:masterfrom
wendigo:user/serafin/index-of-byte

Conversation

@wendigo

@wendigo wendigo commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@wendigo
wendigo requested review from dain and martint July 12, 2026 14:42
@wendigo

wendigo commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

I have use-case for these two methods

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Slice adds bounded indexOfByte overloads and a private helper for searching within an exclusive end bound. Byte searches now use shared 8-byte chunk matching helpers, including indexOfAnyByte and lastIndexOfByte. Brute-force string search uses the new helper. Tests cover bounded searches, empty and invalid regions, multiple-byte searches across offsets, and high-bit byte values.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/main/java/io/airlift/slice/Slice.java (1)

1147-1184: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding @throws javadoc for the new region-bounded overloads and indexOfAnyByte.

Every other indexed accessor in this class (getByte, getShort, getInt, etc.) documents its IndexOutOfBoundsException contract. The new indexOfByte(int, offset, length), indexOfByte(byte, offset, length) (lines 1107-1121), and indexOfAnyByte (lines 1142-1146) only describe the return value, not the bounds-check behavior verified by the new tests.

✏️ Example addition
     /**
      * Returns the index of the first occurrence of the byte within the specified
      * region of this slice. If the byte is not found -1 is returned.
+     *
+     * `@throws` IndexOutOfBoundsException if offset or length is negative, or offset + length is greater than this.length()
      */
     public int indexOfByte(byte b, int offset, int length)

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 12508c77-4505-4009-a95f-6daea6136a26

📥 Commits

Reviewing files that changed from the base of the PR and between 95a137d and a355274.

📒 Files selected for processing (2)
  • src/main/java/io/airlift/slice/Slice.java
  • src/test/java/io/airlift/slice/TestSlice.java

@dain
dain merged commit 484d964 into airlift:master Jul 14, 2026
2 checks passed
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