Skip to content

Commit

Permalink
Added comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lemire committed Jul 6, 2023
1 parent 5de866f commit 7538bf8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion include/ada/percent_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ struct AVX2 {
struct AVX512 {
[[gnu::target("avx512f,avx512bw,avx512vbmi,avx512vbmi2")]] static size_t
percent_decode(char const *in, size_t inputsize, char *out) {

const __m512i byte_plus = _mm512_set1_epi8('+');
const __m512i byte_percent = _mm512_set1_epi8('%');

Expand Down
11 changes: 8 additions & 3 deletions src/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,16 @@ bool percent_encode(const std::string_view input, const uint8_t character_set[],

bool to_ascii(std::optional<std::string>& out, const std::string_view plain,
size_t first_percent) {
std::string percent_decoded_buffer(plain.size(), 0);
std::string percent_decoded_buffer;
std::string_view input = plain;
if (first_percent != std::string_view::npos) {
size_t output_size = percent_decoder::percent_decode(plain.data(), plain.size(), percent_decoded_buffer.data());
percent_decoded_buffer.resize(output_size);
// The indeed code does full percent decoding (over all of plain),
// but it seems more suitable to skip over the prefix before the first "%"
// since in many cases, we might expect percent encoding to be sparse.
percent_decoded_buffer.assign(input.substr(0, first_percent));
percent_decoded_buffer.resize(plain.size());
size_t output_size = percent_decoder::percent_decode(plain.data() + first_percent, plain.size() - first_percent, percent_decoded_buffer.data() + first_percent);
percent_decoded_buffer.resize(output_size + first_percent);
input = percent_decoded_buffer;
}
// input is a non-empty UTF-8 string, must be percent decoded
Expand Down

0 comments on commit 7538bf8

Please sign in to comment.