feat: replace public byteAt with private byteAt_ and add O(1) bytes.count

Remove the public `byteAt(_)` method from String and its ByteSequence wrapper, renaming it to the private `byteAt_(_)` to eliminate redundancy with `.bytes[_]`. Add a native `byteCount_` primitive on String and expose it as `count` on StringByteSequence, enabling O(1) byte length queries. Update all test files to use the new `.bytes` subscript API and add a dedicated `count.wren` test for the new functionality.
This commit is contained in:
Bob Nystrom
2015-09-11 06:52:18 +00:00
parent 0397da2451
commit 731e1f4b1d
9 changed files with 40 additions and 57 deletions
+10 -10
View File
@@ -1,12 +1,12 @@
var s = "\x00\x12\x34\x56\x78\xab\xCD\xfFf"
var bytes = "\x00\x12\x34\x56\x78\xab\xCD\xfFf".bytes
IO.print(s.byteAt(0)) // expect: 0
IO.print(s.byteAt(1)) // expect: 18
IO.print(s.byteAt(2)) // expect: 52
IO.print(s.byteAt(3)) // expect: 86
IO.print(s.byteAt(4)) // expect: 120
IO.print(s.byteAt(5)) // expect: 171
IO.print(s.byteAt(6)) // expect: 205
IO.print(s.byteAt(7)) // expect: 255
IO.print(bytes[0]) // expect: 0
IO.print(bytes[1]) // expect: 18
IO.print(bytes[2]) // expect: 52
IO.print(bytes[3]) // expect: 86
IO.print(bytes[4]) // expect: 120
IO.print(bytes[5]) // expect: 171
IO.print(bytes[6]) // expect: 205
IO.print(bytes[7]) // expect: 255
// "f".
IO.print(s.byteAt(8)) // expect: 102
IO.print(bytes[8]) // expect: 102