You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2026/04/19 07:41:29 UTC

[PR] Fix early-exit bound in indexOf(elem, from, to) [pekko]

pjfanning opened a new pull request, #2876:
URL: https://github.com/apache/pekko/pull/2876

   After scanning the tail bytes (remainder < 8), `ByteString1C` and `ByteString1` both checked `offset == length` instead of `offset >= toIndex` to decide whether to skip the SWAR loop. When `toIndex < length` and the entire search range fits in the tail bytes, the SWAR loop was entered unnecessarily (with `longCount == 0`), missing the early exit.
   
   Not a correctness bug — `longCount` is 0 so the loop body never executes — but a missed optimization.
   
   ## Changes
   
   - **`ByteString1C.indexOf(Byte, from, to)`** (~line 289): `offset == length` → `offset >= toIndex`
   - **`ByteString1.indexOf(Byte, from, to)`** (~line 672): same fix
   
   ## Tests
   
   Added cases to `"indexOf from/to"` in `ByteStringSpec` targeting the exact path: `ByteString` with `length > 8`, search range with `toIndex < length` and `searchLength < 8` (all in tail bytes, `longCount == 0`). Covers both `ByteString1C` (compact) and `ByteString1` (with `startIndex` offset).
   
   ```scala
   // length=26, search range [0,5): searchLength=5 < 8, toIndex=5 < length=26
   val bs = ByteString1.fromString("abcdefghijklmnopqrstuvwxyz").compact
   bs.indexOf('e'.toByte, 0, 5)  // 4   — last in-range hit
   bs.indexOf('f'.toByte, 0, 5)  // -1  — exactly at toIndex, out of range
   bs.indexOf('z'.toByte, 0, 5)  // -1  — well beyond toIndex
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] Fix early-exit bound in indexOf(elem, from, to) [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #2876:
URL: https://github.com/apache/pekko/pull/2876


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org