aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/string_utils/base64
diff options
context:
space:
mode:
authorAlexey Salmin <alexey.salmin@gmail.com>2022-02-10 16:49:37 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:37 +0300
commit71af077a5dfe7e9f932a508422c2dac81a57ebc0 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/string_utils/base64
parent3c5b1607b38f637d2f3313791ed25c2e080d2647 (diff)
downloadydb-71af077a5dfe7e9f932a508422c2dac81a57ebc0.tar.gz
Restoring authorship annotation for Alexey Salmin <alexey.salmin@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/string_utils/base64')
-rw-r--r--library/cpp/string_utils/base64/base64.cpp66
-rw-r--r--library/cpp/string_utils/base64/bench/main.cpp152
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 d368156033..05c201f0de 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 f6da3de328..10e09bc1c7 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);
+}