TODO(melvinw): add support for shifting at bit granularity Shifts `buf` to the left by `len` bytes and fills in with zeroes. Will shift in 8-byte chunks if `shift` <= 8, othersize, uses std::memmove() and std::memset().
| 55 | // Will shift in 8-byte chunks if `shift` <= 8, othersize, uses |
| 56 | // std::memmove() and std::memset(). |
| 57 | static inline void ShiftBytesLeft(uint8_t *buf, const size_t len, |
| 58 | const size_t shift) { |
| 59 | if (len < sizeof(uint64_t) || shift > sizeof(uint64_t)) { |
| 60 | return ShiftBytesLeftSmall(buf, len, shift); |
| 61 | } |
| 62 | |
| 63 | uint8_t *tmp_buf = buf; |
| 64 | size_t tmp_len = len; |
| 65 | size_t inc = sizeof(uint64_t) - shift; |
| 66 | while (tmp_len >= sizeof(uint64_t)) { |
| 67 | uint64_t *block = reinterpret_cast<uint64_t *>(tmp_buf); |
| 68 | *block >>= shift * 8; |
| 69 | tmp_buf += inc; |
| 70 | tmp_len = buf + len - tmp_buf; |
| 71 | } |
| 72 | |
| 73 | buf += len; |
| 74 | if (static_cast<size_t>(buf - tmp_buf) > shift) { |
| 75 | tmp_len = buf - tmp_buf - shift; |
| 76 | memmove(tmp_buf, tmp_buf + shift, tmp_len); |
| 77 | memset(buf - shift, 0, shift); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // TODO(melvinw): add support for shifting at bit granularity |
| 82 | // Shifts `buf` to the right by `len` bytes and fills in with zeroes using |