diff options
| author | Alexey Salmin <[email protected]> | 2022-02-10 16:49:37 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:49:37 +0300 | 
| commit | 3c5b1607b38f637d2f3313791ed25c2e080d2647 (patch) | |
| tree | 99be7b96e7c66612fbca94331100ef3b5fedcb88 /library/cpp/string_utils/base64 | |
| parent | de89752358147d7b25ef59a85b431bb564068a49 (diff) | |
Restoring authorship annotation for Alexey Salmin <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/string_utils/base64')
| -rw-r--r-- | library/cpp/string_utils/base64/base64.cpp | 66 | ||||
| -rw-r--r-- | library/cpp/string_utils/base64/bench/main.cpp | 152 | 
2 files changed, 109 insertions, 109 deletions
| diff --git a/library/cpp/string_utils/base64/base64.cpp b/library/cpp/string_utils/base64/base64.cpp index 05c201f0de7..d3681560336 100644 --- a/library/cpp/string_utils/base64/base64.cpp +++ b/library/cpp/string_utils/base64/base64.cpp @@ -95,46 +95,46 @@ static_assert(Y_ARRAY_SIZE(base64_bkw) == 256, "wrong size");  // Base64 for url encoding, RFC3548  static const char base64_etab_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; -static inline unsigned char GetBase64EncodedIndex0(unsigned char octet0) { -    return (octet0 >> 2); -} - -static inline unsigned char GetBase64EncodedIndex1(unsigned char octet0, unsigned char octet1) { -    return (((octet0 << 4) & 0x30) | ((octet1 >> 4) & 0x0f)); -} - -static inline unsigned char GetBase64EncodedIndex2(unsigned char octet1, unsigned char octet2) { -    return (((octet1 << 2) & 0x3c) | ((octet2 >> 6) & 0x03)); -} - -static inline unsigned char GetBase64EncodedIndex3(unsigned char octet2) { -    return (octet2 & 0x3f); -} - +static inline unsigned char GetBase64EncodedIndex0(unsigned char octet0) {  +    return (octet0 >> 2);  +}  +  +static inline unsigned char GetBase64EncodedIndex1(unsigned char octet0, unsigned char octet1) {  +    return (((octet0 << 4) & 0x30) | ((octet1 >> 4) & 0x0f));  +}  +  +static inline unsigned char GetBase64EncodedIndex2(unsigned char octet1, unsigned char octet2) {  +    return (((octet1 << 2) & 0x3c) | ((octet2 >> 6) & 0x03));  +}  +  +static inline unsigned char GetBase64EncodedIndex3(unsigned char octet2) {  +    return (octet2 & 0x3f);  +}  +   template <bool urlVersion>  static inline char* Base64EncodeImpl(char* outstr, const unsigned char* instr, size_t len) { -    const char* const base64_etab = (urlVersion ? base64_etab_url : base64_etab_std); -    const char pad = (urlVersion ? ',' : '='); +    const char* const base64_etab = (urlVersion ? base64_etab_url : base64_etab_std);  +    const char pad = (urlVersion ? ',' : '=');       size_t idx = 0; -    while (idx + 2 < len) { -        *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])]; -        *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])]; -        *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], instr[idx + 2])]; -        *outstr++ = base64_etab[GetBase64EncodedIndex3(instr[idx + 2])]; -        idx += 3; -    } -    if (idx < len) { -        *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])]; -        if (idx + 1 < len) { -            *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])]; -            *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], '\0')]; +    while (idx + 2 < len) {  +        *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])];  +        *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])];  +        *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], instr[idx + 2])];  +        *outstr++ = base64_etab[GetBase64EncodedIndex3(instr[idx + 2])];  +        idx += 3;  +    }  +    if (idx < len) {  +        *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])];  +        if (idx + 1 < len) {  +            *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])];  +            *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], '\0')];           } else { -            *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], '\0')]; -            *outstr++ = pad; +            *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], '\0')];  +            *outstr++ = pad;           } -        *outstr++ = pad; +        *outstr++ = pad;       }      *outstr = 0; diff --git a/library/cpp/string_utils/base64/bench/main.cpp b/library/cpp/string_utils/base64/bench/main.cpp index 10e09bc1c75..f6da3de3280 100644 --- a/library/cpp/string_utils/base64/bench/main.cpp +++ b/library/cpp/string_utils/base64/bench/main.cpp @@ -105,19 +105,19 @@ static inline void BenchEncode(T& d, const NBench::NCpu::TParams& iface) {  }  template <typename T> -static inline void BenchEncodeUrl(T& d, const NBench::NCpu::TParams& iface) { -    for (const auto it : xrange(iface.Iterations())) { -        Y_UNUSED(it); -        for (size_t i = 0; i < d.Size; ++i) { +static inline void BenchEncodeUrl(T& d, const NBench::NCpu::TParams& iface) {  +    for (const auto it : xrange(iface.Iterations())) {  +        Y_UNUSED(it);  +        for (size_t i = 0; i < d.Size; ++i) {               NBench::Escape(d.PlaceToEncode[i].data()); -            Y_DO_NOT_OPTIMIZE_AWAY( +            Y_DO_NOT_OPTIMIZE_AWAY(                   Base64EncodeUrl(d.PlaceToEncode[i].data(), (const unsigned char*)d.Data[i].data(), d.Data[i].size())); -            NBench::Clobber(); -        } -    } -} - -template <typename T> +            NBench::Clobber();  +        }  +    }  +}  +  +template <typename T>   static inline void BenchDecode(T& d, const NBench::NCpu::TParams& iface) {      for (const auto it : xrange(iface.Iterations())) {          Y_UNUSED(it); @@ -259,68 +259,68 @@ Y_CPU_BENCHMARK(DecodeF10485760, iface) {      auto& d = *Singleton<FSRDH_10485760>();      BenchDecode(d, iface);  } - -Y_CPU_BENCHMARK(EncodeUrlF1, iface) { -    auto& d = *Singleton<FSRDH_1>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF2, iface) { -    auto& d = *Singleton<FSRDH_2>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF4, iface) { -    auto& d = *Singleton<FSRDH_4>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF8, iface) { -    auto& d = *Singleton<FSRDH_8>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF16, iface) { -    auto& d = *Singleton<FSRDH_16>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF32, iface) { -    auto& d = *Singleton<FSRDH_32>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF64, iface) { -    auto& d = *Singleton<FSRDH_64>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF128, iface) { -    auto& d = *Singleton<FSRDH_128>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF1024, iface) { -    auto& d = *Singleton<FSRDH_1024>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF10240, iface) { -    auto& d = *Singleton<FSRDH_10240>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF102400, iface) { -    auto& d = *Singleton<FSRDH_102400>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF1048576, iface) { -    auto& d = *Singleton<FSRDH_1048576>(); -    BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF10485760, iface) { -    auto& d = *Singleton<FSRDH_10485760>(); -    BenchEncodeUrl(d, iface); -} +  +Y_CPU_BENCHMARK(EncodeUrlF1, iface) {  +    auto& d = *Singleton<FSRDH_1>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF2, iface) {  +    auto& d = *Singleton<FSRDH_2>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF4, iface) {  +    auto& d = *Singleton<FSRDH_4>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF8, iface) {  +    auto& d = *Singleton<FSRDH_8>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF16, iface) {  +    auto& d = *Singleton<FSRDH_16>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF32, iface) {  +    auto& d = *Singleton<FSRDH_32>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF64, iface) {  +    auto& d = *Singleton<FSRDH_64>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF128, iface) {  +    auto& d = *Singleton<FSRDH_128>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF1024, iface) {  +    auto& d = *Singleton<FSRDH_1024>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF10240, iface) {  +    auto& d = *Singleton<FSRDH_10240>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF102400, iface) {  +    auto& d = *Singleton<FSRDH_102400>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF1048576, iface) {  +    auto& d = *Singleton<FSRDH_1048576>();  +    BenchEncodeUrl(d, iface);  +}  +  +Y_CPU_BENCHMARK(EncodeUrlF10485760, iface) {  +    auto& d = *Singleton<FSRDH_10485760>();  +    BenchEncodeUrl(d, iface);  +}  | 
