| 95 | |
| 96 | |
| 97 | static void force_ascii(const char* src, char* dst, size_t len) { |
| 98 | if (len < 16) { |
| 99 | force_ascii_slow(src, dst, len); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | const unsigned bytes_per_word = sizeof(void*); |
| 104 | const unsigned align_mask = bytes_per_word - 1; |
| 105 | const unsigned src_unalign = reinterpret_cast<uintptr_t>(src) & align_mask; |
| 106 | const unsigned dst_unalign = reinterpret_cast<uintptr_t>(dst) & align_mask; |
| 107 | |
| 108 | if (src_unalign > 0) { |
| 109 | if (src_unalign == dst_unalign) { |
| 110 | const unsigned unalign = bytes_per_word - src_unalign; |
| 111 | force_ascii_slow(src, dst, unalign); |
| 112 | src += unalign; |
| 113 | dst += unalign; |
| 114 | len -= src_unalign; |
| 115 | } else { |
| 116 | force_ascii_slow(src, dst, len); |
| 117 | return; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | #if defined(__x86_64__) || defined(_WIN64) |
| 122 | const uintptr_t mask = ~0x8080808080808080ll; |
| 123 | #else |
| 124 | const uintptr_t mask = ~0x80808080l; |
| 125 | #endif |
| 126 | |
| 127 | const uintptr_t* srcw = reinterpret_cast<const uintptr_t*>(src); |
| 128 | uintptr_t* dstw = reinterpret_cast<uintptr_t*>(dst); |
| 129 | |
| 130 | for (size_t i = 0, n = len / bytes_per_word; i < n; ++i) { |
| 131 | dstw[i] = srcw[i] & mask; |
| 132 | } |
| 133 | |
| 134 | const unsigned remainder = len & align_mask; |
| 135 | if (remainder > 0) { |
| 136 | const size_t offset = len - remainder; |
| 137 | force_ascii_slow(src + offset, dst + offset, remainder); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | |
| 142 | static size_t base64_encode(const char* src, |
no test coverage detected