indexByte returns the index of the first instance of c in buffer, or -1 if c is not present in buffer.
(c byte, skip int)
| 750 | |
| 751 | // indexByte returns the index of the first instance of c in buffer, or -1 if c is not present in buffer. |
| 752 | func (b *UnsafeLinkBuffer) indexByte(c byte, skip int) int { |
| 753 | size := b.Len() |
| 754 | if skip >= size { |
| 755 | return -1 |
| 756 | } |
| 757 | var unread, n, l int |
| 758 | node := b.read |
| 759 | for unread = size; unread > 0; unread -= n { |
| 760 | l = node.Len() |
| 761 | if l >= unread { // last node |
| 762 | n = unread |
| 763 | } else { // read full node |
| 764 | n = l |
| 765 | } |
| 766 | |
| 767 | // skip current node |
| 768 | if skip >= n { |
| 769 | skip -= n |
| 770 | node = node.next |
| 771 | continue |
| 772 | } |
| 773 | i := bytes.IndexByte(node.Peek(n)[skip:], c) |
| 774 | if i >= 0 { |
| 775 | return (size - unread) + skip + i // past_read + skip_read + index |
| 776 | } |
| 777 | skip = 0 // no skip bytes |
| 778 | node = node.next |
| 779 | } |
| 780 | return -1 |
| 781 | } |
| 782 | |
| 783 | // ------------------------------------------ private function ------------------------------------------ |
| 784 |