Exact output size, so the "old" arm gets a buffer large enough to complete.
| 78 | |
| 79 | // Exact output size, so the "old" arm gets a buffer large enough to complete. |
| 80 | int32_t ExactCapacity(const std::string& text, const char* from, int flen, int olen) { |
| 81 | int64_t matches = 0; |
| 82 | auto tlen = static_cast<int32_t>(text.size()); |
| 83 | if (flen > 0 && flen <= tlen) { |
| 84 | for (int32_t i = 0; i <= tlen - flen;) { |
| 85 | if (memcmp(text.data() + i, from, flen) == 0) { |
| 86 | ++matches; |
| 87 | i += flen; |
| 88 | } else { |
| 89 | ++i; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | return static_cast<int32_t>(tlen + matches * (olen - flen)); |
| 94 | } |
| 95 | |
| 96 | void BM_ReplaceNew(benchmark::State& state) { |
| 97 | const ReplaceCase& c = Cases()[state.range(0)]; |
no test coverage detected