BytesNext returns the next possible byte slice, using the extra capacity of the provided slice if possible, and if not, appending an \x00.
(b []byte)
| 3769 | // BytesNext returns the next possible byte slice, using the extra capacity |
| 3770 | // of the provided slice if possible, and if not, appending an \x00. |
| 3771 | func BytesNext(b []byte) []byte { |
| 3772 | if cap(b) > len(b) { |
| 3773 | bNext := b[:len(b)+1] |
| 3774 | if bNext[len(bNext)-1] == 0 { |
| 3775 | return bNext |
| 3776 | } |
| 3777 | } |
| 3778 | // TODO(spencer): Do we need to enforce KeyMaxLength here? |
| 3779 | // Switched to "make and copy" pattern in #4963 for performance. |
| 3780 | bn := make([]byte, len(b)+1) |
| 3781 | copy(bn, b) |
| 3782 | bn[len(bn)-1] = 0 |
| 3783 | return bn |
| 3784 | } |
| 3785 | |
| 3786 | // BytesPrevish returns a previous byte slice in lexicographical ordering. It is |
| 3787 | // impossible in general to find the exact previous byte slice, because it has |