From a3f184d9064c49803380da280ddd65155fdb0410 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Tue, 27 Apr 2021 16:59:21 +0800 Subject: [PATCH 01/10] src,lib,buffer: improve atob / btoa performance Extract `modp_b64` dependence from Chromium to improve performance of `atob()` and `btoa()`. Refs: https://github.com/chromium/chromium/tree/92.0.4490.1/third_party/modp_b64 --- benchmark/buffers/buffer-atob.js | 44 +++ benchmark/buffers/buffer-btoa.js | 42 +++ deps/modp_b64/LICENSE | 33 +++ deps/modp_b64/README.chromium | 17 ++ deps/modp_b64/modp_b64.cc | 253 ++++++++++++++++ deps/modp_b64/modp_b64.gyp | 13 + deps/modp_b64/modp_b64.h | 171 +++++++++++ deps/modp_b64/modp_b64_data.h | 481 +++++++++++++++++++++++++++++++ lib/buffer.js | 36 +-- node.gyp | 1 + node.gypi | 4 + src/node_buffer.cc | 83 ++++++ src/node_errors.h | 2 + test/parallel/test-btoa-atob.js | 35 +++ 14 files changed, 1198 insertions(+), 17 deletions(-) create mode 100644 benchmark/buffers/buffer-atob.js create mode 100644 benchmark/buffers/buffer-btoa.js create mode 100644 deps/modp_b64/LICENSE create mode 100644 deps/modp_b64/README.chromium create mode 100644 deps/modp_b64/modp_b64.cc create mode 100644 deps/modp_b64/modp_b64.gyp create mode 100644 deps/modp_b64/modp_b64.h create mode 100644 deps/modp_b64/modp_b64_data.h create mode 100644 test/parallel/test-btoa-atob.js diff --git a/benchmark/buffers/buffer-atob.js b/benchmark/buffers/buffer-atob.js new file mode 100644 index 00000000000000..ed8b6d96a3c38a --- /dev/null +++ b/benchmark/buffers/buffer-atob.js @@ -0,0 +1,44 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; +const buffer = require('buffer'); +const common = require('../common.js'); + +const bench = common.createBenchmark(main, { + len: [64 * 1024 ], + n: [32] +}, { + test: { len: 256 } +}); + +function main({ n, len }) { + let s = ''; + let large = ''; + let i; + for (i = 0; i < 256; ++i) s += String.fromCharCode(i); + for (i = 0; i < len; i += 256) large += s; + const b64 = btoa(large); + + bench.start(); + for (i = 0; i < n; ++i) buffer.atob(b64); + bench.end(n); +} diff --git a/benchmark/buffers/buffer-btoa.js b/benchmark/buffers/buffer-btoa.js new file mode 100644 index 00000000000000..b0db9ca31c2631 --- /dev/null +++ b/benchmark/buffers/buffer-btoa.js @@ -0,0 +1,42 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; +const buffer = require('buffer'); +const common = require('../common.js'); + +const bench = common.createBenchmark(main, { + len: [64 * 1024 * 1024], + n: [32] +}, { + test: { len: 256 } +}); + +function main({ n, len }) { + let s = ''; + let large = ''; + let i; + for (i = 0; i < 256; ++i) s += String.fromCharCode(i); + for (i = 0; i < len; i += 256) large += s; + bench.start(); + for (i = 0; i < n; ++i) buffer.btoa(large); + bench.end(n); +} diff --git a/deps/modp_b64/LICENSE b/deps/modp_b64/LICENSE new file mode 100644 index 00000000000000..55af76f3eb690d --- /dev/null +++ b/deps/modp_b64/LICENSE @@ -0,0 +1,33 @@ + * MODP_B64 - High performance base64 encoder/decoder + * Version 1.3 -- 17-Mar-2006 + * http://modp.com/release/base64 + * + * Copyright (c) 2005, 2006 Nick Galbreath -- nickg [at] modp [dot] com + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the modp.com nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/deps/modp_b64/README.chromium b/deps/modp_b64/README.chromium new file mode 100644 index 00000000000000..364a0507373f90 --- /dev/null +++ b/deps/modp_b64/README.chromium @@ -0,0 +1,17 @@ +Name: modp base64 decoder +Short Name: stringencoders +URL: https://github.com/client9/stringencoders +Version: unknown +License: BSD +Security Critical: yes + +Description: +The modp_b64.c file was modified to remove the inclusion of modp's config.h +and to fix compilation errors that occur under VC8. The file was renamed +modp_b64.cc to force it to be compiled as C++ so that the inclusion of +basictypes.h could be possible. + +The modp_b64.cc and modp_b64.h files were modified to make them safe on +64-bit systems. +The modp_b64.cc was modified to avoid misaligned read/write on +little-endian hardware. diff --git a/deps/modp_b64/modp_b64.cc b/deps/modp_b64/modp_b64.cc new file mode 100644 index 00000000000000..fdb8a40ec7d28a --- /dev/null +++ b/deps/modp_b64/modp_b64.cc @@ -0,0 +1,253 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set expandtab shiftwidth=4 tabstop=4: */ +/** + * \file + *
+ * MODP_B64 - High performance base64 encoder/decoder
+ * Version 1.3 -- 17-Mar-2006
+ * http://modp.com/release/base64
+ *
+ * Copyright © 2005, 2006  Nick Galbreath -- nickg [at] modp [dot] com
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *   Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ *   Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ *   Neither the name of the modp.com nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This is the standard "new" BSD license:
+ * http://www.opensource.org/licenses/bsd-license.php
+ * 
+ */ + +/* public header */ +#include "modp_b64.h" + +/* + * If you are ripping this out of the library, comment out the next + * line and uncomment the next lines as approrpiate + */ +//#include "config.h" + +/* if on motoral, sun, ibm; uncomment this */ +/* #define WORDS_BIGENDIAN 1 */ +/* else for Intel, Amd; uncomment this */ +/* #undef WORDS_BIGENDIAN */ + +#include "modp_b64_data.h" + +#define BADCHAR 0x01FFFFFF + +/** + * you can control if we use padding by commenting out this + * next line. However, I highly recommend you use padding and not + * using it should only be for compatability with a 3rd party. + * Also, 'no padding' is not tested! + */ +#define DOPAD 1 + +/* + * if we aren't doing padding + * set the pad character to NULL + */ +#ifndef DOPAD +#undef CHARPAD +#define CHARPAD '\0' +#endif + +size_t modp_b64_encode(char* dest, const char* str, size_t len) +{ + size_t i = 0; + uint8_t* p = (uint8_t*) dest; + + /* unsigned here is important! */ + uint8_t t1, t2, t3; + + if (len > 2) { + for (; i < len - 2; i += 3) { + t1 = str[i]; t2 = str[i+1]; t3 = str[i+2]; + *p++ = e0[t1]; + *p++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)]; + *p++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)]; + *p++ = e2[t3]; + } + } + + switch (len - i) { + case 0: + break; + case 1: + t1 = str[i]; + *p++ = e0[t1]; + *p++ = e1[(t1 & 0x03) << 4]; + *p++ = CHARPAD; + *p++ = CHARPAD; + break; + default: /* case 2 */ + t1 = str[i]; t2 = str[i+1]; + *p++ = e0[t1]; + *p++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)]; + *p++ = e2[(t2 & 0x0F) << 2]; + *p++ = CHARPAD; + } + + *p = '\0'; + return p - (uint8_t*)dest; +} + +#ifdef WORDS_BIGENDIAN /* BIG ENDIAN -- SUN / IBM / MOTOROLA */ +int modp_b64_decode(char* dest, const char* src, int len) +{ + if (len == 0) return 0; + +#ifdef DOPAD + /* if padding is used, then the message must be at least + 4 chars and be a multiple of 4. + there can be at most 2 pad chars at the end */ + if (len < 4 || (len % 4 != 0)) return MODP_B64_ERROR; + if (src[len-1] == CHARPAD) { + len--; + if (src[len -1] == CHARPAD) { + len--; + } + } +#endif /* DOPAD */ + + size_t i; + int leftover = len % 4; + size_t chunks = (leftover == 0) ? len / 4 - 1 : len /4; + + uint8_t* p = (uint8_t*) dest; + uint32_t x = 0; + uint32_t* destInt = (uint32_t*) p; + uint32_t* srcInt = (uint32_t*) src; + uint32_t y = *srcInt++; + for (i = 0; i < chunks; ++i) { + x = d0[y >> 24 & 0xff] | d1[y >> 16 & 0xff] | + d2[y >> 8 & 0xff] | d3[y & 0xff]; + + if (x >= BADCHAR) return MODP_B64_ERROR; + *destInt = x << 8; + p += 3; + destInt = (uint32_t*)p; + y = *srcInt++; + } + + switch (leftover) { + case 0: + x = d0[y >> 24 & 0xff] | d1[y >> 16 & 0xff] | + d2[y >> 8 & 0xff] | d3[y & 0xff]; + if (x >= BADCHAR) return MODP_B64_ERROR; + *p++ = ((uint8_t*)&x)[1]; + *p++ = ((uint8_t*)&x)[2]; + *p = ((uint8_t*)&x)[3]; + return (chunks+1)*3; + case 1: + x = d3[y >> 24]; + *p = (uint8_t)x; + break; + case 2: + x = d3[y >> 24] *64 + d3[(y >> 16) & 0xff]; + *p = (uint8_t)(x >> 4); + break; + default: /* case 3 */ + x = (d3[y >> 24] *64 + d3[(y >> 16) & 0xff])*64 + + d3[(y >> 8) & 0xff]; + *p++ = (uint8_t) (x >> 10); + *p = (uint8_t) (x >> 2); + break; + } + + if (x >= BADCHAR) return MODP_B64_ERROR; + return 3*chunks + (6*leftover)/8; +} + +#else /* LITTLE ENDIAN -- INTEL AND FRIENDS */ + +size_t modp_b64_decode(char* dest, const char* src, size_t len) +{ + if (len == 0) return 0; + +#ifdef DOPAD + /* + * if padding is used, then the message must be at least + * 4 chars and be a multiple of 4 + */ + if (len < 4 || (len % 4 != 0)) return MODP_B64_ERROR; /* error */ + /* there can be at most 2 pad chars at the end */ + if (src[len-1] == CHARPAD) { + len--; + if (src[len -1] == CHARPAD) { + len--; + } + } +#endif + + size_t i; + int leftover = len % 4; + size_t chunks = (leftover == 0) ? len / 4 - 1 : len /4; + + uint8_t* p = (uint8_t*)dest; + uint32_t x = 0; + const uint8_t* y = (uint8_t*)src; + for (i = 0; i < chunks; ++i, y += 4) { + x = d0[y[0]] | d1[y[1]] | d2[y[2]] | d3[y[3]]; + if (x >= BADCHAR) return MODP_B64_ERROR; + *p++ = ((uint8_t*)(&x))[0]; + *p++ = ((uint8_t*)(&x))[1]; + *p++ = ((uint8_t*)(&x))[2]; + } + + switch (leftover) { + case 0: + x = d0[y[0]] | d1[y[1]] | d2[y[2]] | d3[y[3]]; + + if (x >= BADCHAR) return MODP_B64_ERROR; + *p++ = ((uint8_t*)(&x))[0]; + *p++ = ((uint8_t*)(&x))[1]; + *p = ((uint8_t*)(&x))[2]; + return (chunks+1)*3; + break; + case 1: /* with padding this is an impossible case */ + x = d0[y[0]]; + *p = *((uint8_t*)(&x)); // i.e. first char/byte in int + break; + case 2: // * case 2, 1 output byte */ + x = d0[y[0]] | d1[y[1]]; + *p = *((uint8_t*)(&x)); // i.e. first char + break; + default: /* case 3, 2 output bytes */ + x = d0[y[0]] | d1[y[1]] | d2[y[2]]; /* 0x3c */ + *p++ = ((uint8_t*)(&x))[0]; + *p = ((uint8_t*)(&x))[1]; + break; + } + + if (x >= BADCHAR) return MODP_B64_ERROR; + + return 3*chunks + (6*leftover)/8; +} + +#endif /* if bigendian / else / endif */ diff --git a/deps/modp_b64/modp_b64.gyp b/deps/modp_b64/modp_b64.gyp new file mode 100644 index 00000000000000..652aedfb067981 --- /dev/null +++ b/deps/modp_b64/modp_b64.gyp @@ -0,0 +1,13 @@ +{ + 'targets': [ + { + 'target_name': 'modp_b64', + 'type': 'static_library', + 'include_dirs': [ '.' ], + 'direct_dependent_settings': { + 'include_dirs': [ '.' ], + }, + 'sources': [ 'modp_b64.cc' ], + }, + ] +} diff --git a/deps/modp_b64/modp_b64.h b/deps/modp_b64/modp_b64.h new file mode 100644 index 00000000000000..074b901b5e7274 --- /dev/null +++ b/deps/modp_b64/modp_b64.h @@ -0,0 +1,171 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ +/* vi: set expandtab shiftwidth=4 tabstop=4: */ + +/** + * \file + *
+ * High performance base64 encoder / decoder
+ * Version 1.3 -- 17-Mar-2006
+ *
+ * Copyright © 2005, 2006, Nick Galbreath -- nickg [at] modp [dot] com
+ * All rights reserved.
+ *
+ * http://modp.com/release/base64
+ *
+ * Released under bsd license.  See modp_b64.c for details.
+ * 
+ * + * The default implementation is the standard b64 encoding with padding. + * It's easy to change this to use "URL safe" characters and to remove + * padding. See the modp_b64.c source code for details. + * + */ + +#ifndef MODP_B64 +#define MODP_B64 + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Encode a raw binary string into base 64. + * src contains the bytes + * len contains the number of bytes in the src + * dest should be allocated by the caller to contain + * at least modp_b64_encode_len(len) bytes (see below) + * This will contain the null-terminated b64 encoded result + * returns length of the destination string plus the ending null byte + * i.e. the result will be equal to strlen(dest) + 1 + * + * Example + * + * \code + * char* src = ...; + * int srclen = ...; //the length of number of bytes in src + * char* dest = (char*) malloc(modp_b64_encode_len); + * int len = modp_b64_encode(dest, src, sourcelen); + * if (len == -1) { + * printf("Error\n"); + * } else { + * printf("b64 = %s\n", dest); + * } + * \endcode + * + */ +size_t modp_b64_encode(char* dest, const char* str, size_t len); + +/** + * Decode a base64 encoded string + * + * src should contain exactly len bytes of b64 characters. + * if src contains -any- non-base characters (such as white + * space, -1 is returned. + * + * dest should be allocated by the caller to contain at least + * len * 3 / 4 bytes. + * + * Returns the length (strlen) of the output, or -1 if unable to + * decode + * + * \code + * char* src = ...; + * int srclen = ...; // or if you don't know use strlen(src) + * char* dest = (char*) malloc(modp_b64_decode_len(srclen)); + * int len = modp_b64_decode(dest, src, sourcelen); + * if (len == -1) { error } + * \endcode + */ +size_t modp_b64_decode(char* dest, const char* src, size_t len); + +/** + * Given a source string of length len, this returns the amount of + * memory the destination string should have. + * + * remember, this is integer math + * 3 bytes turn into 4 chars + * ceiling[len / 3] * 4 + 1 + * + * +1 is for any extra null. + */ +#define modp_b64_encode_len(A) ((A+2)/3 * 4 + 1) + +/** + * Given a base64 string of length len, + * this returns the amount of memory required for output string + * It maybe be more than the actual number of bytes written. + * NOTE: remember this is integer math + * this allocates a bit more memory than traditional versions of b64 + * decode 4 chars turn into 3 bytes + * floor[len * 3/4] + 2 + */ +#define modp_b64_decode_len(A) (A / 4 * 3 + 2) + +/** + * Will return the strlen of the output from encoding. + * This may be less than the required number of bytes allocated. + * + * This allows you to 'deserialized' a struct + * \code + * char* b64encoded = "..."; + * int len = strlen(b64encoded); + * + * struct datastuff foo; + * if (modp_b64_encode_strlen(sizeof(struct datastuff)) != len) { + * // wrong size + * return false; + * } else { + * // safe to do; + * if (modp_b64_decode((char*) &foo, b64encoded, len) == -1) { + * // bad characters + * return false; + * } + * } + * // foo is filled out now + * \endcode + */ +#define modp_b64_encode_strlen(A) ((A + 2)/ 3 * 4) + +#define MODP_B64_ERROR ((size_t)-1) + +#ifdef __cplusplus +} + +#include + +inline std::string& modp_b64_encode(std::string& s) +{ + std::string x(modp_b64_encode_len(s.size()), '\0'); + size_t d = modp_b64_encode(const_cast(x.data()), s.data(), (int)s.size()); + x.erase(d, std::string::npos); + s.swap(x); + return s; +} + +/** + * base 64 decode a string (self-modifing) + * On failure, the string is empty. + * + * This function is for C++ only (duh) + * + * \param[in,out] s the string to be decoded + * \return a reference to the input string + */ +inline std::string& modp_b64_decode(std::string& s) +{ + std::string x(modp_b64_decode_len(s.size()), '\0'); + size_t d = modp_b64_decode(const_cast(x.data()), s.data(), (int)s.size()); + if (d == MODP_B64_ERROR) { + x.clear(); + } else { + x.erase(d, std::string::npos); + } + s.swap(x); + return s; +} + +#endif /* __cplusplus */ + +#endif /* MODP_B64 */ diff --git a/deps/modp_b64/modp_b64_data.h b/deps/modp_b64/modp_b64_data.h new file mode 100644 index 00000000000000..2ecf5977b9ec8c --- /dev/null +++ b/deps/modp_b64/modp_b64_data.h @@ -0,0 +1,481 @@ +#include + +#define CHAR62 '+' +#define CHAR63 '/' +#define CHARPAD '=' +static const char e0[256] = { + 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'C', 'C', + 'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'E', + 'F', 'F', 'F', 'F', 'G', 'G', 'G', 'G', 'H', 'H', + 'H', 'H', 'I', 'I', 'I', 'I', 'J', 'J', 'J', 'J', + 'K', 'K', 'K', 'K', 'L', 'L', 'L', 'L', 'M', 'M', + 'M', 'M', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O', + 'P', 'P', 'P', 'P', 'Q', 'Q', 'Q', 'Q', 'R', 'R', + 'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T', + 'U', 'U', 'U', 'U', 'V', 'V', 'V', 'V', 'W', 'W', + 'W', 'W', 'X', 'X', 'X', 'X', 'Y', 'Y', 'Y', 'Y', + 'Z', 'Z', 'Z', 'Z', 'a', 'a', 'a', 'a', 'b', 'b', + 'b', 'b', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd', + 'e', 'e', 'e', 'e', 'f', 'f', 'f', 'f', 'g', 'g', + 'g', 'g', 'h', 'h', 'h', 'h', 'i', 'i', 'i', 'i', + 'j', 'j', 'j', 'j', 'k', 'k', 'k', 'k', 'l', 'l', + 'l', 'l', 'm', 'm', 'm', 'm', 'n', 'n', 'n', 'n', + 'o', 'o', 'o', 'o', 'p', 'p', 'p', 'p', 'q', 'q', + 'q', 'q', 'r', 'r', 'r', 'r', 's', 's', 's', 's', + 't', 't', 't', 't', 'u', 'u', 'u', 'u', 'v', 'v', + 'v', 'v', 'w', 'w', 'w', 'w', 'x', 'x', 'x', 'x', + 'y', 'y', 'y', 'y', 'z', 'z', 'z', 'z', '0', '0', + '0', '0', '1', '1', '1', '1', '2', '2', '2', '2', + '3', '3', '3', '3', '4', '4', '4', '4', '5', '5', + '5', '5', '6', '6', '6', '6', '7', '7', '7', '7', + '8', '8', '8', '8', '9', '9', '9', '9', '+', '+', + '+', '+', '/', '/', '/', '/' +}; + +static const char e1[256] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', + 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', + 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '+', '/', 'A', 'B', + 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', + 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', + 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', + 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', + 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', '+', '/' +}; + +static const char e2[256] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', + 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', + 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '+', '/', 'A', 'B', + 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', + 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', + 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', + 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', + 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', '+', '/' +}; + + + +#ifdef WORDS_BIGENDIAN + + +/* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */ + +static const uint32_t d0[256] = { +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x00f80000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00fc0000, +0x00d00000, 0x00d40000, 0x00d80000, 0x00dc0000, 0x00e00000, 0x00e40000, +0x00e80000, 0x00ec0000, 0x00f00000, 0x00f40000, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, +0x00040000, 0x00080000, 0x000c0000, 0x00100000, 0x00140000, 0x00180000, +0x001c0000, 0x00200000, 0x00240000, 0x00280000, 0x002c0000, 0x00300000, +0x00340000, 0x00380000, 0x003c0000, 0x00400000, 0x00440000, 0x00480000, +0x004c0000, 0x00500000, 0x00540000, 0x00580000, 0x005c0000, 0x00600000, +0x00640000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x00680000, 0x006c0000, 0x00700000, 0x00740000, 0x00780000, +0x007c0000, 0x00800000, 0x00840000, 0x00880000, 0x008c0000, 0x00900000, +0x00940000, 0x00980000, 0x009c0000, 0x00a00000, 0x00a40000, 0x00a80000, +0x00ac0000, 0x00b00000, 0x00b40000, 0x00b80000, 0x00bc0000, 0x00c00000, +0x00c40000, 0x00c80000, 0x00cc0000, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff +}; + + +static const uint32_t d1[256] = { +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x0003e000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0003f000, +0x00034000, 0x00035000, 0x00036000, 0x00037000, 0x00038000, 0x00039000, +0x0003a000, 0x0003b000, 0x0003c000, 0x0003d000, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, +0x00001000, 0x00002000, 0x00003000, 0x00004000, 0x00005000, 0x00006000, +0x00007000, 0x00008000, 0x00009000, 0x0000a000, 0x0000b000, 0x0000c000, +0x0000d000, 0x0000e000, 0x0000f000, 0x00010000, 0x00011000, 0x00012000, +0x00013000, 0x00014000, 0x00015000, 0x00016000, 0x00017000, 0x00018000, +0x00019000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x0001a000, 0x0001b000, 0x0001c000, 0x0001d000, 0x0001e000, +0x0001f000, 0x00020000, 0x00021000, 0x00022000, 0x00023000, 0x00024000, +0x00025000, 0x00026000, 0x00027000, 0x00028000, 0x00029000, 0x0002a000, +0x0002b000, 0x0002c000, 0x0002d000, 0x0002e000, 0x0002f000, 0x00030000, +0x00031000, 0x00032000, 0x00033000, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff +}; + + +static const uint32_t d2[256] = { +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x00000f80, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000fc0, +0x00000d00, 0x00000d40, 0x00000d80, 0x00000dc0, 0x00000e00, 0x00000e40, +0x00000e80, 0x00000ec0, 0x00000f00, 0x00000f40, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, +0x00000040, 0x00000080, 0x000000c0, 0x00000100, 0x00000140, 0x00000180, +0x000001c0, 0x00000200, 0x00000240, 0x00000280, 0x000002c0, 0x00000300, +0x00000340, 0x00000380, 0x000003c0, 0x00000400, 0x00000440, 0x00000480, +0x000004c0, 0x00000500, 0x00000540, 0x00000580, 0x000005c0, 0x00000600, +0x00000640, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x00000680, 0x000006c0, 0x00000700, 0x00000740, 0x00000780, +0x000007c0, 0x00000800, 0x00000840, 0x00000880, 0x000008c0, 0x00000900, +0x00000940, 0x00000980, 0x000009c0, 0x00000a00, 0x00000a40, 0x00000a80, +0x00000ac0, 0x00000b00, 0x00000b40, 0x00000b80, 0x00000bc0, 0x00000c00, +0x00000c40, 0x00000c80, 0x00000cc0, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff +}; + + +static const uint32_t d3[256] = { +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x0000003e, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0000003f, +0x00000034, 0x00000035, 0x00000036, 0x00000037, 0x00000038, 0x00000039, +0x0000003a, 0x0000003b, 0x0000003c, 0x0000003d, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, +0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, +0x00000007, 0x00000008, 0x00000009, 0x0000000a, 0x0000000b, 0x0000000c, +0x0000000d, 0x0000000e, 0x0000000f, 0x00000010, 0x00000011, 0x00000012, +0x00000013, 0x00000014, 0x00000015, 0x00000016, 0x00000017, 0x00000018, +0x00000019, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x0000001a, 0x0000001b, 0x0000001c, 0x0000001d, 0x0000001e, +0x0000001f, 0x00000020, 0x00000021, 0x00000022, 0x00000023, 0x00000024, +0x00000025, 0x00000026, 0x00000027, 0x00000028, 0x00000029, 0x0000002a, +0x0000002b, 0x0000002c, 0x0000002d, 0x0000002e, 0x0000002f, 0x00000030, +0x00000031, 0x00000032, 0x00000033, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff +}; + + +#else + + +/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */ + +static const uint32_t d0[256] = { +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x000000f8, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x000000fc, +0x000000d0, 0x000000d4, 0x000000d8, 0x000000dc, 0x000000e0, 0x000000e4, +0x000000e8, 0x000000ec, 0x000000f0, 0x000000f4, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, +0x00000004, 0x00000008, 0x0000000c, 0x00000010, 0x00000014, 0x00000018, +0x0000001c, 0x00000020, 0x00000024, 0x00000028, 0x0000002c, 0x00000030, +0x00000034, 0x00000038, 0x0000003c, 0x00000040, 0x00000044, 0x00000048, +0x0000004c, 0x00000050, 0x00000054, 0x00000058, 0x0000005c, 0x00000060, +0x00000064, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x00000068, 0x0000006c, 0x00000070, 0x00000074, 0x00000078, +0x0000007c, 0x00000080, 0x00000084, 0x00000088, 0x0000008c, 0x00000090, +0x00000094, 0x00000098, 0x0000009c, 0x000000a0, 0x000000a4, 0x000000a8, +0x000000ac, 0x000000b0, 0x000000b4, 0x000000b8, 0x000000bc, 0x000000c0, +0x000000c4, 0x000000c8, 0x000000cc, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff +}; + + +static const uint32_t d1[256] = { +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x0000e003, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0000f003, +0x00004003, 0x00005003, 0x00006003, 0x00007003, 0x00008003, 0x00009003, +0x0000a003, 0x0000b003, 0x0000c003, 0x0000d003, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, +0x00001000, 0x00002000, 0x00003000, 0x00004000, 0x00005000, 0x00006000, +0x00007000, 0x00008000, 0x00009000, 0x0000a000, 0x0000b000, 0x0000c000, +0x0000d000, 0x0000e000, 0x0000f000, 0x00000001, 0x00001001, 0x00002001, +0x00003001, 0x00004001, 0x00005001, 0x00006001, 0x00007001, 0x00008001, +0x00009001, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x0000a001, 0x0000b001, 0x0000c001, 0x0000d001, 0x0000e001, +0x0000f001, 0x00000002, 0x00001002, 0x00002002, 0x00003002, 0x00004002, +0x00005002, 0x00006002, 0x00007002, 0x00008002, 0x00009002, 0x0000a002, +0x0000b002, 0x0000c002, 0x0000d002, 0x0000e002, 0x0000f002, 0x00000003, +0x00001003, 0x00002003, 0x00003003, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff +}; + + +static const uint32_t d2[256] = { +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x00800f00, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00c00f00, +0x00000d00, 0x00400d00, 0x00800d00, 0x00c00d00, 0x00000e00, 0x00400e00, +0x00800e00, 0x00c00e00, 0x00000f00, 0x00400f00, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, +0x00400000, 0x00800000, 0x00c00000, 0x00000100, 0x00400100, 0x00800100, +0x00c00100, 0x00000200, 0x00400200, 0x00800200, 0x00c00200, 0x00000300, +0x00400300, 0x00800300, 0x00c00300, 0x00000400, 0x00400400, 0x00800400, +0x00c00400, 0x00000500, 0x00400500, 0x00800500, 0x00c00500, 0x00000600, +0x00400600, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x00800600, 0x00c00600, 0x00000700, 0x00400700, 0x00800700, +0x00c00700, 0x00000800, 0x00400800, 0x00800800, 0x00c00800, 0x00000900, +0x00400900, 0x00800900, 0x00c00900, 0x00000a00, 0x00400a00, 0x00800a00, +0x00c00a00, 0x00000b00, 0x00400b00, 0x00800b00, 0x00c00b00, 0x00000c00, +0x00400c00, 0x00800c00, 0x00c00c00, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff +}; + + +static const uint32_t d3[256] = { +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x003e0000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x003f0000, +0x00340000, 0x00350000, 0x00360000, 0x00370000, 0x00380000, 0x00390000, +0x003a0000, 0x003b0000, 0x003c0000, 0x003d0000, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, +0x00010000, 0x00020000, 0x00030000, 0x00040000, 0x00050000, 0x00060000, +0x00070000, 0x00080000, 0x00090000, 0x000a0000, 0x000b0000, 0x000c0000, +0x000d0000, 0x000e0000, 0x000f0000, 0x00100000, 0x00110000, 0x00120000, +0x00130000, 0x00140000, 0x00150000, 0x00160000, 0x00170000, 0x00180000, +0x00190000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x001a0000, 0x001b0000, 0x001c0000, 0x001d0000, 0x001e0000, +0x001f0000, 0x00200000, 0x00210000, 0x00220000, 0x00230000, 0x00240000, +0x00250000, 0x00260000, 0x00270000, 0x00280000, 0x00290000, 0x002a0000, +0x002b0000, 0x002c0000, 0x002d0000, 0x002e0000, 0x002f0000, 0x00300000, +0x00310000, 0x00320000, 0x00330000, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, +0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff +}; + + +#endif diff --git a/lib/buffer.js b/lib/buffer.js index 951805870c5870..71c2c8399b398d 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -63,7 +63,9 @@ const { swap32: _swap32, swap64: _swap64, kMaxLength, - kStringMaxLength + kStringMaxLength, + btoa: _btoa, + atob: _atob, } = internalBinding('buffer'); const { getOwnNonIndexProperties, @@ -1220,29 +1222,29 @@ const lazyInvalidCharError = hideStackFrames((message, name) => { }); function btoa(input) { - // TODO(@jasnell): The implementation here has not been performance - // optimized in any way. input = `${input}`; - for (let n = 0; n < input.length; n++) { - if (input[n].charCodeAt(0) > 0xff) - lazyInvalidCharError(); + let ret; + try { + ret = _btoa(input); + } catch (e) { + if (DOMException === undefined) + DOMException = internalBinding('messaging').DOMException; + throw new DOMException('Invalid character', 'InvalidCharacterError'); } - const buf = Buffer.from(input, 'latin1'); - return buf.toString('base64'); + return ret; } -const kBase64Digits = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - function atob(input) { - // TODO(@jasnell): The implementation here has not been performance - // optimized in any way. input = `${input}`; - for (let n = 0; n < input.length; n++) { - if (!kBase64Digits.includes(input[n])) - lazyInvalidCharError(); + let ret; + try { + ret = _atob(input); + } catch (e) { + if (DOMException === undefined) + DOMException = internalBinding('messaging').DOMException; + throw new DOMException('Invalid character', 'InvalidCharacterError'); } - return Buffer.from(input, 'base64').toString('latin1'); + return ret; } module.exports = { diff --git a/node.gyp b/node.gyp index 3308ecb432c34f..2057aafe686358 100644 --- a/node.gyp +++ b/node.gyp @@ -20,6 +20,7 @@ 'node_shared_cares%': 'false', 'node_shared_libuv%': 'false', 'node_shared_nghttp2%': 'false', + 'node_shared_modp_b64%': 'false', 'node_use_openssl%': 'true', 'node_shared_openssl%': 'false', 'node_v8_options%': '', diff --git a/node.gypi b/node.gypi index a3c927956ec53f..aa712f3c780f2d 100644 --- a/node.gypi +++ b/node.gypi @@ -191,6 +191,10 @@ 'dependencies': [ 'deps/brotli/brotli.gyp:brotli' ], }], + [ 'node_shared_modp_b64=="false"', { + 'dependencies': [ 'deps/modp_b64/modp_b64.gyp:modp_b64' ], + }], + [ 'OS=="mac"', { # linking Corefoundation is needed since certain OSX debugging tools # like Instruments require it for some features diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 9006c1de767533..374a152195f9e9 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -32,6 +32,7 @@ #include "string_search.h" #include "util-inl.h" #include "v8.h" +#include "modp_b64.h" #include #include @@ -1158,6 +1159,82 @@ void GetZeroFillToggle(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(Uint32Array::New(ab, 0, 1)); } +void BToA(const FunctionCallbackInfo& args) { + CHECK(args[0]->IsString()); + Environment* env = Environment::GetCurrent(args); + Isolate* isolate = env->isolate(); + Local input = args[0].As(); + + if (!input->IsOneByte()) { + env->isolate()->ThrowException(ERR_INVALID_CHARACTER(env->isolate())); + return; + } + + node::Utf8Value input_utf8_value(isolate, input); + + // Check latin + std::string input_str = input_utf8_value.ToString(); + + size_t max_dest_len = modp_b64_encode_len(input_str.length()) + 1; + char* dest = static_cast(malloc(max_dest_len * sizeof(char))); + int dest_len = modp_b64_encode(dest, input_str.c_str(), input_str.length()); + + if (dest_len == -1) { + free(dest); + env->isolate()->ThrowException(ERR_INVALID_CHARACTER(env->isolate())); + return; + } + + dest[dest_len] = 0; + MaybeLocal maybe_dest = String::NewFromUtf8( + isolate, + dest, + v8::NewStringType::kNormal, + dest_len); + CHECK(!maybe_dest.IsEmpty()); + args.GetReturnValue().Set(maybe_dest.ToLocalChecked()); + + free(dest); +} + +void AToB(const FunctionCallbackInfo& args) { + CHECK(args[0]->IsString()); + Environment* env = Environment::GetCurrent(args); + Isolate* isolate = env->isolate(); + Local input = args[0].As(); + + if (!input->IsOneByte()) { + env->isolate()->ThrowException(ERR_INVALID_CHARACTER(env->isolate())); + return; + } + + node::Utf8Value input_utf8_value(isolate, input); + + // Check latin + std::string input_str = input_utf8_value.ToString(); + + size_t max_dest_len = modp_b64_decode_len(input_str.length()) + 1; + char* dest = static_cast(malloc(max_dest_len * sizeof(char))); + + int dest_len = modp_b64_decode(dest, input_str.c_str(), input_str.length()); + if (dest_len == -1) { + free(dest); + env->isolate()->ThrowException(ERR_INVALID_CHARACTER(env->isolate())); + return; + } + + dest[dest_len] = 0; + MaybeLocal maybe_dest = String::NewFromOneByte( + isolate, + reinterpret_cast(dest), + v8::NewStringType::kNormal, + dest_len); + CHECK(!maybe_dest.IsEmpty()); + args.GetReturnValue().Set(maybe_dest.ToLocalChecked()); + + free(dest); +} + void Initialize(Local target, Local unused, Local context, @@ -1209,6 +1286,9 @@ void Initialize(Local target, env->SetMethod(target, "getZeroFillToggle", GetZeroFillToggle); + env->SetMethod(target, "btoa", BToA); + env->SetMethod(target, "atob", AToB); + Blob::Initialize(env, target); } @@ -1251,6 +1331,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(StringWrite); registry->Register(GetZeroFillToggle); + registry->Register(BToA); + registry->Register(AToB); + Blob::RegisterExternalReferences(registry); FixedSizeBlobCopyJob::RegisterExternalReferences(registry); } diff --git a/src/node_errors.h b/src/node_errors.h index 291365fa3b4dc9..cea34010c8d6c0 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -60,6 +60,7 @@ void OnFatalError(const char* location, const char* message); V(ERR_INVALID_ARG_VALUE, TypeError) \ V(ERR_OSSL_EVP_INVALID_DIGEST, Error) \ V(ERR_INVALID_ARG_TYPE, TypeError) \ + V(ERR_INVALID_CHARACTER, RangeError) \ V(ERR_INVALID_MODULE, Error) \ V(ERR_INVALID_THIS, TypeError) \ V(ERR_INVALID_TRANSFER_OBJECT, TypeError) \ @@ -145,6 +146,7 @@ ERRORS_WITH_CODE(V) V(ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE, \ "Context not associated with Node.js environment") \ V(ERR_INVALID_ADDRESS, "Invalid socket address") \ + V(ERR_INVALID_CHARACTER, "Invalid character") \ V(ERR_INVALID_MODULE, "No such module") \ V(ERR_INVALID_THIS, "Value of \"this\" is the wrong type") \ V(ERR_INVALID_TRANSFER_OBJECT, "Found invalid object in transferList") \ diff --git a/test/parallel/test-btoa-atob.js b/test/parallel/test-btoa-atob.js new file mode 100644 index 00000000000000..20dacfe2fd0b71 --- /dev/null +++ b/test/parallel/test-btoa-atob.js @@ -0,0 +1,35 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); + +let s1 = ''; +for (let i = 0; i < 256; ++i) s1 += String.fromCharCode(i); +const s1B64 = Buffer.from(s1).toString('base64'); + +assert.strictEqual(btoa(s1), s1B64); + +const s2 = 'hello world'; +const s2B64 = Buffer.from(s2).toString('base64'); +assert.strictEqual(btoa(s2), s2B64); + +const s3 = 'BlingBling...'; +const s3B64 = Buffer.from(s3).toString('base64'); +assert.strictEqual(btoa(s3), s3B64); + +const s4 = '哇咔咔'; +const s4B64 = Buffer.from(s4).toString('base64'); +assert.throws(() => { btoa(s4) }, { + name: 'InvalidCharacterError', + message: 'Invalid character', + code: 5, +}); + +assert.strictEqual(atob(s1B64), + Buffer.from(s1B64, 'base64').toString('latin1')); +assert.strictEqual(atob(s2B64), + Buffer.from(s2B64, 'base64').toString('latin1')); +assert.strictEqual(atob(s3B64), + Buffer.from(s3B64, 'base64').toString('latin1')); +assert.strictEqual(atob(s4B64), + Buffer.from(s4B64, 'base64').toString('latin1')); From beceed4c63bc5c221a2d220baef5c508142ffbc9 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Tue, 27 Apr 2021 18:31:30 +0800 Subject: [PATCH 02/10] f --- lib/buffer.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 71c2c8399b398d..ab66f8a9d6a98c 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1215,12 +1215,6 @@ if (internalBinding('config').hasIntl) { let DOMException; -const lazyInvalidCharError = hideStackFrames((message, name) => { - if (DOMException === undefined) - DOMException = internalBinding('messaging').DOMException; - throw new DOMException('Invalid character', 'InvalidCharacterError'); -}); - function btoa(input) { input = `${input}`; let ret; @@ -1229,7 +1223,9 @@ function btoa(input) { } catch (e) { if (DOMException === undefined) DOMException = internalBinding('messaging').DOMException; - throw new DOMException('Invalid character', 'InvalidCharacterError'); + let code = 'Error'; + if (e.code === 'ERR_INVALID_CHARACTER') code = 'InvalidCharacterError'; + throw new DOMException(e.message, code); } return ret; } @@ -1242,7 +1238,9 @@ function atob(input) { } catch (e) { if (DOMException === undefined) DOMException = internalBinding('messaging').DOMException; - throw new DOMException('Invalid character', 'InvalidCharacterError'); + let code = 'Error'; + if (e.code === 'ERR_INVALID_CHARACTER') code = 'InvalidCharacterError'; + throw new DOMException(e.message, code); } return ret; } From 5cb24c8d1d09ed625add45370759931bedefd4a4 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Tue, 27 Apr 2021 18:32:18 +0800 Subject: [PATCH 03/10] f --- test/parallel/test-btoa-atob.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/parallel/test-btoa-atob.js b/test/parallel/test-btoa-atob.js index 20dacfe2fd0b71..e8f124704844f8 100644 --- a/test/parallel/test-btoa-atob.js +++ b/test/parallel/test-btoa-atob.js @@ -1,6 +1,5 @@ 'use strict'; -const common = require('../common'); const assert = require('assert'); let s1 = ''; @@ -19,7 +18,7 @@ assert.strictEqual(btoa(s3), s3B64); const s4 = '哇咔咔'; const s4B64 = Buffer.from(s4).toString('base64'); -assert.throws(() => { btoa(s4) }, { +assert.throws(() => { btoa(s4); }, { name: 'InvalidCharacterError', message: 'Invalid character', code: 5, From b42b4bac8c471403dc972c5cf3c4ad85fa9ea7fe Mon Sep 17 00:00:00 2001 From: XadillaX Date: Tue, 27 Apr 2021 18:39:27 +0800 Subject: [PATCH 04/10] f --- test/parallel/test-btoa-atob.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-btoa-atob.js b/test/parallel/test-btoa-atob.js index e8f124704844f8..120f98e36f8a2b 100644 --- a/test/parallel/test-btoa-atob.js +++ b/test/parallel/test-btoa-atob.js @@ -1,5 +1,6 @@ 'use strict'; +require('../common'); const assert = require('assert'); let s1 = ''; From 63b9a4917fb0666352c7da15bdf833505f5cf1dd Mon Sep 17 00:00:00 2001 From: XadillaX Date: Wed, 28 Apr 2021 20:29:20 +0800 Subject: [PATCH 05/10] f --- node.gyp | 1 - node.gypi | 4 - src/base64-inl.h | 113 +++++++++++----- src/base64.h | 27 ++-- src/node_buffer.cc | 311 +++++++++++++++++++-------------------------- 5 files changed, 225 insertions(+), 231 deletions(-) diff --git a/node.gyp b/node.gyp index 2057aafe686358..3308ecb432c34f 100644 --- a/node.gyp +++ b/node.gyp @@ -20,7 +20,6 @@ 'node_shared_cares%': 'false', 'node_shared_libuv%': 'false', 'node_shared_nghttp2%': 'false', - 'node_shared_modp_b64%': 'false', 'node_use_openssl%': 'true', 'node_shared_openssl%': 'false', 'node_v8_options%': '', diff --git a/node.gypi b/node.gypi index aa712f3c780f2d..a3c927956ec53f 100644 --- a/node.gypi +++ b/node.gypi @@ -191,10 +191,6 @@ 'dependencies': [ 'deps/brotli/brotli.gyp:brotli' ], }], - [ 'node_shared_modp_b64=="false"', { - 'dependencies': [ 'deps/modp_b64/modp_b64.gyp:modp_b64' ], - }], - [ 'OS=="mac"', { # linking Corefoundation is needed since certain OSX debugging tools # like Instruments require it for some features diff --git a/src/base64-inl.h b/src/base64-inl.h index 1b6cdd93f002a4..c57ccf672a3245 100644 --- a/src/base64-inl.h +++ b/src/base64-inl.h @@ -10,17 +10,14 @@ namespace node { extern const int8_t unbase64_table[256]; - inline static int8_t unbase64(uint8_t x) { return unbase64_table[x]; } - inline uint32_t ReadUint32BE(const unsigned char* p) { return static_cast(p[0] << 24U) | static_cast(p[1] << 16U) | - static_cast(p[2] << 8U) | - static_cast(p[3]); + static_cast(p[2] << 8U) | static_cast(p[3]); } #ifdef _MSC_VER @@ -30,9 +27,12 @@ inline uint32_t ReadUint32BE(const unsigned char* p) { #endif template -bool base64_decode_group_slow(char* const dst, const size_t dstlen, - const TypeName* const src, const size_t srclen, - size_t* const i, size_t* const k) { +bool base64_decode_group_slow(char* const dst, + const size_t dstlen, + const TypeName* const src, + const size_t srclen, + size_t* const i, + size_t* const k) { uint8_t hi; uint8_t lo; #define V(expr) \ @@ -60,9 +60,21 @@ bool base64_decode_group_slow(char* const dst, const size_t dstlen, #endif template -size_t base64_decode_fast(char* const dst, const size_t dstlen, - const TypeName* const src, const size_t srclen, - const size_t decoded_size) { +size_t base64_decode_fast(char* const dst, + const size_t dstlen, + const TypeName* const src, + size_t srclen, + const size_t decoded_size, + bool* succ, + const bool strict) { + CHECK(!strict || succ != nullptr); + + if (static_cast(src[srclen - 1]) == '=') { + srclen--; + if (static_cast(src[srclen - 1]) == '=') srclen--; + } + + if (succ != nullptr) *succ = true; const size_t available = dstlen < decoded_size ? dstlen : decoded_size; const size_t max_k = available / 3 * 3; size_t max_i = srclen / 4 * 4; @@ -79,52 +91,93 @@ size_t base64_decode_fast(char* const dst, const size_t dstlen, const uint32_t v = ReadUint32BE(txt); // If MSB is set, input contains whitespace or is not valid base64. if (v & 0x80808080) { - if (!base64_decode_group_slow(dst, dstlen, src, srclen, &i, &k)) - return k; + if (strict) { + *succ = false; + return 0; + } + if (!base64_decode_group_slow(dst, dstlen, src, srclen, &i, &k)) return k; max_i = i + (srclen - i) / 4 * 4; // Align max_i again. } else { dst[k + 0] = ((v >> 22) & 0xFC) | ((v >> 20) & 0x03); dst[k + 1] = ((v >> 12) & 0xF0) | ((v >> 10) & 0x0F); - dst[k + 2] = ((v >> 2) & 0xC0) | ((v >> 0) & 0x3F); + dst[k + 2] = ((v >> 2) & 0xC0) | ((v >> 0) & 0x3F); i += 4; k += 3; } } + if (i < srclen && k < dstlen) { +#define CHECK_INVALID(x) \ + if (txt[(x)] & 0x80) { \ + if (strict) { \ + *succ = false; \ + return 0; \ + } else { \ + break; \ + } \ + } + + int leftover = srclen - i; + unsigned char txt[] = {0, 0, 0, 0}; + switch (leftover) { + case 4: + txt[3] = static_cast( + unbase64(static_cast(src[i + 3]))); + CHECK_INVALID(3); + // DO NOT break; + + case 3: + txt[2] = static_cast( + unbase64(static_cast(src[i + 2]))); + CHECK_INVALID(2); + // DO NOT break; + + case 2: + txt[1] = static_cast( + unbase64(static_cast(src[i + 1]))); + CHECK_INVALID(1); + // DO NOT break; + + default: + txt[0] = static_cast( + unbase64(static_cast(src[i + 0]))); + CHECK_INVALID(0); + } + +#undef CHECK_INVALID + base64_decode_group_slow(dst, dstlen, src, srclen, &i, &k); } + return k; } - template size_t base64_decoded_size(const TypeName* src, size_t size) { // 1-byte input cannot be decoded - if (size < 2) - return 0; + if (size < 2) return 0; if (src[size - 1] == '=') { size--; - if (src[size - 1] == '=') - size--; + if (src[size - 1] == '=') size--; } return base64_decoded_size_fast(size); } - template -size_t base64_decode(char* const dst, const size_t dstlen, - const TypeName* const src, const size_t srclen) { +size_t base64_decode(char* const dst, + const size_t dstlen, + const TypeName* const src, + const size_t srclen, + bool* succ, + const bool strict) { const size_t decoded_size = base64_decoded_size(src, srclen); - return base64_decode_fast(dst, dstlen, src, srclen, decoded_size); + return base64_decode_fast( + dst, dstlen, src, srclen, decoded_size, succ, strict); } - -inline size_t base64_encode(const char* src, - size_t slen, - char* dst, - size_t dlen, - Base64Mode mode) { +inline size_t base64_encode( + const char* src, size_t slen, char* dst, size_t dlen, Base64Mode mode) { // We know how much we'll write, just make sure that there's space. CHECK(dlen >= base64_encoded_size(slen, mode) && "not enough space provided for base64 encode"); @@ -174,8 +227,7 @@ inline size_t base64_encode(const char* src, dst[k + 0] = table[a >> 2]; dst[k + 1] = table[((a & 3) << 4) | (b >> 4)]; dst[k + 2] = table[(b & 0x0f) << 2]; - if (mode == Base64Mode::NORMAL) - dst[k + 3] = '='; + if (mode == Base64Mode::NORMAL) dst[k + 3] = '='; break; } @@ -185,5 +237,4 @@ inline size_t base64_encode(const char* src, } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - #endif // SRC_BASE64_INL_H_ diff --git a/src/base64.h b/src/base64.h index 0db096810cd4a8..8ea92f105b188f 100644 --- a/src/base64.h +++ b/src/base64.h @@ -12,10 +12,7 @@ namespace node { //// Base 64 //// -enum class Base64Mode { - NORMAL, - URL -}; +enum class Base64Mode { NORMAL, URL }; static constexpr char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" @@ -27,15 +24,17 @@ static constexpr char base64_table_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" static inline const char* base64_select_table(Base64Mode mode) { switch (mode) { - case Base64Mode::NORMAL: return base64_table; - case Base64Mode::URL: return base64_table_url; - default: UNREACHABLE(); + case Base64Mode::NORMAL: + return base64_table; + case Base64Mode::URL: + return base64_table_url; + default: + UNREACHABLE(); } } static inline constexpr size_t base64_encoded_size( - size_t size, - Base64Mode mode = Base64Mode::NORMAL) { + size_t size, Base64Mode mode = Base64Mode::NORMAL) { return mode == Base64Mode::NORMAL ? ((size + 2) / 3 * 4) : static_cast(std::ceil( static_cast(size * 4) / 3)); @@ -53,8 +52,12 @@ template size_t base64_decoded_size(const TypeName* src, size_t size); template -size_t base64_decode(char* const dst, const size_t dstlen, - const TypeName* const src, const size_t srclen); +size_t base64_decode(char* const dst, + const size_t dstlen, + const TypeName* const src, + size_t srclen, + bool* succ = nullptr, + const bool strict = false); inline size_t base64_encode(const char* src, size_t slen, @@ -63,7 +66,5 @@ inline size_t base64_encode(const char* src, Base64Mode mode = Base64Mode::NORMAL); } // namespace node - #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - #endif // SRC_BASE64_H_ diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 374a152195f9e9..c464eb9638b229 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -27,25 +27,25 @@ #include "node_external_reference.h" #include "node_internals.h" +#include "base64-inl.h" #include "env-inl.h" #include "string_bytes.h" #include "string_search.h" #include "util-inl.h" #include "v8.h" -#include "modp_b64.h" -#include #include +#include -#define THROW_AND_RETURN_UNLESS_BUFFER(env, obj) \ - THROW_AND_RETURN_IF_NOT_BUFFER(env, obj, "argument") \ +#define THROW_AND_RETURN_UNLESS_BUFFER(env, obj) \ + THROW_AND_RETURN_IF_NOT_BUFFER(env, obj, "argument") -#define THROW_AND_RETURN_IF_OOB(r) \ - do { \ - if ((r).IsNothing()) return; \ - if (!(r).FromJust()) \ - return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \ - } while (0) \ +#define THROW_AND_RETURN_IF_OOB(r) \ + do { \ + if ((r).IsNothing()) return; \ + if (!(r).FromJust()) \ + return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \ + } while (0) namespace node { namespace Buffer { @@ -104,21 +104,22 @@ class CallbackInfo { Environment* const env_; }; - -Local CallbackInfo::CreateTrackedArrayBuffer( - Environment* env, - char* data, - size_t length, - FreeCallback callback, - void* hint) { +Local CallbackInfo::CreateTrackedArrayBuffer(Environment* env, + char* data, + size_t length, + FreeCallback callback, + void* hint) { CHECK_NOT_NULL(callback); CHECK_IMPLIES(data == nullptr, length == 0); CallbackInfo* self = new CallbackInfo(env, callback, data, hint); - std::unique_ptr bs = - ArrayBuffer::NewBackingStore(data, length, [](void*, size_t, void* arg) { + std::unique_ptr bs = ArrayBuffer::NewBackingStore( + data, + length, + [](void*, size_t, void* arg) { static_cast(arg)->OnBackingStoreFree(); - }, self); + }, + self); Local ab = ArrayBuffer::New(env->isolate(), std::move(bs)); // V8 simply ignores the BackingStore deleter callback if data == nullptr, @@ -135,15 +136,11 @@ Local CallbackInfo::CreateTrackedArrayBuffer( return ab; } - CallbackInfo::CallbackInfo(Environment* env, FreeCallback callback, char* data, void* hint) - : callback_(callback), - data_(data), - hint_(hint), - env_(env) { + : callback_(callback), data_(data), hint_(hint), env_(env) { env->AddCleanupHook(CleanupHook, this); env->isolate()->AdjustAmountOfExternalAllocatedMemory(sizeof(*this)); } @@ -184,7 +181,7 @@ void CallbackInfo::CallAndResetCallback() { void CallbackInfo::OnBackingStoreFree() { // This method should always release the memory for `this`. - std::unique_ptr self { this }; + std::unique_ptr self{this}; Mutex::ScopedLock lock(mutex_); // If callback_ == nullptr, that means that the callback has already run from // the cleanup hook, and there is nothing left to do here besides to clean @@ -199,7 +196,6 @@ void CallbackInfo::OnBackingStoreFree() { }); } - // Parse index for external array data. An empty Maybe indicates // a pending exception. `false` indicates that the index is out-of-bounds. inline MUST_USE_RESULT Maybe ParseArrayIndex(Environment* env, @@ -212,17 +208,14 @@ inline MUST_USE_RESULT Maybe ParseArrayIndex(Environment* env, } int64_t tmp_i; - if (!arg->IntegerValue(env->context()).To(&tmp_i)) - return Nothing(); + if (!arg->IntegerValue(env->context()).To(&tmp_i)) return Nothing(); - if (tmp_i < 0) - return Just(false); + if (tmp_i < 0) return Just(false); // Check that the result fits in a size_t. const uint64_t kSizeMax = static_cast(static_cast(-1)); // coverity[pointless_expression] - if (static_cast(tmp_i) > kSizeMax) - return Just(false); + if (static_cast(tmp_i) > kSizeMax) return Just(false); *ret = static_cast(tmp_i); return Just(true); @@ -236,39 +229,33 @@ bool HasInstance(Local val) { return val->IsArrayBufferView(); } - bool HasInstance(Local obj) { return obj->IsArrayBufferView(); } - char* Data(Local val) { CHECK(val->IsArrayBufferView()); Local ui = val.As(); return static_cast(ui->Buffer()->GetBackingStore()->Data()) + - ui->ByteOffset(); + ui->ByteOffset(); } - char* Data(Local obj) { return Data(obj.As()); } - size_t Length(Local val) { CHECK(val->IsArrayBufferView()); Local ui = val.As(); return ui->ByteLength(); } - size_t Length(Local obj) { CHECK(obj->IsArrayBufferView()); Local ui = obj.As(); return ui->ByteLength(); } - MaybeLocal New(Environment* env, Local ab, size_t byte_offset, @@ -277,8 +264,7 @@ MaybeLocal New(Environment* env, Local ui = Uint8Array::New(ab, byte_offset, length); Maybe mb = ui->SetPrototype(env->context(), env->buffer_prototype_object()); - if (mb.IsNothing()) - return MaybeLocal(); + if (mb.IsNothing()) return MaybeLocal(); return ui; } @@ -294,7 +280,6 @@ MaybeLocal New(Isolate* isolate, return New(env, ab, byte_offset, length); } - MaybeLocal New(Isolate* isolate, Local string, enum encoding enc) { @@ -315,11 +300,7 @@ MaybeLocal New(Isolate* isolate, } actual = StringBytes::Write( - isolate, - static_cast(store->Data()), - length, - string, - enc); + isolate, static_cast(store->Data()), length, string, enc); CHECK(actual <= length); if (LIKELY(actual > 0)) { @@ -336,7 +317,6 @@ MaybeLocal New(Isolate* isolate, return scope.EscapeMaybe(New(isolate, 0)); } - MaybeLocal New(Isolate* isolate, size_t length) { EscapableHandleScope handle_scope(isolate); Local obj; @@ -345,12 +325,10 @@ MaybeLocal New(Isolate* isolate, size_t length) { THROW_ERR_BUFFER_CONTEXT_NOT_AVAILABLE(isolate); return MaybeLocal(); } - if (Buffer::New(env, length).ToLocal(&obj)) - return handle_scope.Escape(obj); + if (Buffer::New(env, length).ToLocal(&obj)) return handle_scope.Escape(obj); return Local(); } - MaybeLocal New(Environment* env, size_t length) { EscapableHandleScope scope(env->isolate()); @@ -364,7 +342,6 @@ MaybeLocal New(Environment* env, size_t length) { AllocatedBuffer::AllocateManaged(env, length).ToBuffer()); } - MaybeLocal Copy(Isolate* isolate, const char* data, size_t length) { EscapableHandleScope handle_scope(isolate); Environment* env = Environment::GetCurrent(isolate); @@ -378,7 +355,6 @@ MaybeLocal Copy(Isolate* isolate, const char* data, size_t length) { return Local(); } - MaybeLocal Copy(Environment* env, const char* data, size_t length) { EscapableHandleScope scope(env->isolate()); @@ -396,7 +372,6 @@ MaybeLocal Copy(Environment* env, const char* data, size_t length) { return scope.EscapeMaybe(ret.ToBuffer()); } - MaybeLocal New(Isolate* isolate, char* data, size_t length, @@ -413,7 +388,6 @@ MaybeLocal New(Isolate* isolate, Buffer::New(env, data, length, callback, hint)); } - MaybeLocal New(Environment* env, char* data, size_t length, @@ -431,14 +405,14 @@ MaybeLocal New(Environment* env, CallbackInfo::CreateTrackedArrayBuffer(env, data, length, callback, hint); if (ab->SetPrivate(env->context(), env->untransferable_object_private_symbol(), - True(env->isolate())).IsNothing()) { + True(env->isolate())) + .IsNothing()) { return Local(); } MaybeLocal maybe_ui = Buffer::New(env, ab, 0, length); Local ui; - if (!maybe_ui.ToLocal(&ui)) - return MaybeLocal(); + if (!maybe_ui.ToLocal(&ui)) return MaybeLocal(); return scope.Escape(ui); } @@ -461,9 +435,7 @@ MaybeLocal New(Isolate* isolate, char* data, size_t length) { // The contract for this function is that `data` is allocated with malloc() // and not necessarily isolate's ArrayBuffer::Allocator. -MaybeLocal New(Environment* env, - char* data, - size_t length) { +MaybeLocal New(Environment* env, char* data, size_t length) { if (length > 0) { CHECK_NOT_NULL(data); CHECK(length <= kMaxLength); @@ -485,7 +457,6 @@ void CreateFromString(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(buf); } - template void StringSlice(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -494,8 +465,7 @@ void StringSlice(const FunctionCallbackInfo& args) { THROW_AND_RETURN_UNLESS_BUFFER(env, args.This()); ArrayBufferViewContents buffer(args.This()); - if (buffer.length() == 0) - return args.GetReturnValue().SetEmptyString(); + if (buffer.length() == 0) return args.GetReturnValue().SetEmptyString(); size_t start = 0; size_t end = 0; @@ -506,12 +476,8 @@ void StringSlice(const FunctionCallbackInfo& args) { size_t length = end - start; Local error; - MaybeLocal maybe_ret = - StringBytes::Encode(isolate, - buffer.data() + start, - length, - encoding, - &error); + MaybeLocal maybe_ret = StringBytes::Encode( + isolate, buffer.data() + start, length, encoding, &error); Local ret; if (!maybe_ret.ToLocal(&ret)) { CHECK(!error.IsEmpty()); @@ -521,9 +487,8 @@ void StringSlice(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(ret); } - // bytesCopied = copy(buffer, target[, targetStart][, sourceStart][, sourceEnd]) -void Copy(const FunctionCallbackInfo &args) { +void Copy(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -538,8 +503,8 @@ void Copy(const FunctionCallbackInfo &args) { THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], 0, &target_start)); THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[3], 0, &source_start)); - THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[4], source.length(), - &source_end)); + THROW_AND_RETURN_IF_OOB( + ParseArrayIndex(env, args[4], source.length(), &source_end)); // Copy 0 bytes; we're done if (target_start >= target_length || source_start >= source_end) @@ -560,7 +525,6 @@ void Copy(const FunctionCallbackInfo &args) { args.GetReturnValue().Set(to_copy); } - void Fill(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Local ctx = env->context(); @@ -632,16 +596,14 @@ void Fill(const FunctionCallbackInfo& args) { start_fill: - if (str_length >= fill_length) - return; + if (str_length >= fill_length) return; // If str_length is zero, then either an empty buffer was provided, or Write() // indicated that no bytes could be written. If no bytes could be written, // then return -1 because the fill value is invalid. This will trigger a throw // in JavaScript. Silently failing should be avoided because it can lead to // buffers with unexpected contents. - if (str_length == 0) - return args.GetReturnValue().Set(-1); + if (str_length == 0) return args.GetReturnValue().Set(-1); size_t in_there = str_length; char* ptr = ts_obj_data + start + str_length; @@ -657,7 +619,6 @@ void Fill(const FunctionCallbackInfo& args) { } } - template void StringWrite(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -678,24 +639,19 @@ void StringWrite(const FunctionCallbackInfo& args) { env, "\"offset\" is outside of buffer bounds"); } - THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], ts_obj_length - offset, - &max_length)); + THROW_AND_RETURN_IF_OOB( + ParseArrayIndex(env, args[2], ts_obj_length - offset, &max_length)); max_length = std::min(ts_obj_length - offset, max_length); - if (max_length == 0) - return args.GetReturnValue().Set(0); + if (max_length == 0) return args.GetReturnValue().Set(0); - uint32_t written = StringBytes::Write(env->isolate(), - ts_obj_data + offset, - max_length, - str, - encoding, - nullptr); + uint32_t written = StringBytes::Write( + env->isolate(), ts_obj_data + offset, max_length, str, encoding, nullptr); args.GetReturnValue().Set(written); } -void ByteLengthUtf8(const FunctionCallbackInfo &args) { +void ByteLengthUtf8(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK(args[0]->IsString()); @@ -720,7 +676,7 @@ static int normalizeCompareVal(int val, size_t a_length, size_t b_length) { return val; } -void CompareOffset(const FunctionCallbackInfo &args) { +void CompareOffset(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -735,10 +691,10 @@ void CompareOffset(const FunctionCallbackInfo &args) { THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], 0, &target_start)); THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[3], 0, &source_start)); - THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[4], target.length(), - &target_end)); - THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[5], source.length(), - &source_end)); + THROW_AND_RETURN_IF_OOB( + ParseArrayIndex(env, args[4], target.length(), &target_end)); + THROW_AND_RETURN_IF_OOB( + ParseArrayIndex(env, args[5], source.length(), &source_end)); if (source_start > source.length()) return THROW_ERR_OUT_OF_RANGE( @@ -754,17 +710,18 @@ void CompareOffset(const FunctionCallbackInfo &args) { std::min(std::min(source_end - source_start, target_end - target_start), source.length() - source_start); - int val = normalizeCompareVal(to_cmp > 0 ? - memcmp(source.data() + source_start, - target.data() + target_start, - to_cmp) : 0, - source_end - source_start, - target_end - target_start); + int val = + normalizeCompareVal(to_cmp > 0 ? memcmp(source.data() + source_start, + target.data() + target_start, + to_cmp) + : 0, + source_end - source_start, + target_end - target_start); args.GetReturnValue().Set(val); } -void Compare(const FunctionCallbackInfo &args) { +void Compare(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -774,13 +731,13 @@ void Compare(const FunctionCallbackInfo &args) { size_t cmp_length = std::min(a.length(), b.length()); - int val = normalizeCompareVal(cmp_length > 0 ? - memcmp(a.data(), b.data(), cmp_length) : 0, - a.length(), b.length()); + int val = normalizeCompareVal( + cmp_length > 0 ? memcmp(a.data(), b.data(), cmp_length) : 0, + a.length(), + b.length()); args.GetReturnValue().Set(val); } - // Computes the offset for starting an indexOf or lastIndexOf search. // Returns either a valid offset in [0...], ie inside the Buffer, // or -1 to signal that there is no possible match. @@ -837,16 +794,15 @@ void IndexOfString(const FunctionCallbackInfo& args) { const char* haystack = buffer.data(); // Round down to the nearest multiple of 2 in case of UCS2. - const size_t haystack_length = (enc == UCS2) ? - buffer.length() &~ 1 : buffer.length(); // NOLINT(whitespace/operators) + const size_t haystack_length = + (enc == UCS2) ? buffer.length() & ~1 + : buffer.length(); // NOLINT(whitespace/operators) size_t needle_length; if (!StringBytes::Size(isolate, needle, enc).To(&needle_length)) return; - int64_t opt_offset = IndexOfOffset(haystack_length, - offset_i64, - needle_length, - is_forward); + int64_t opt_offset = + IndexOfOffset(haystack_length, offset_i64, needle_length, is_forward); if (needle_length == 0) { // Match String#indexOf() and String#lastIndexOf() behavior. @@ -872,8 +828,7 @@ void IndexOfString(const FunctionCallbackInfo& args) { if (enc == UCS2) { String::Value needle_value(isolate, needle); - if (*needle_value == nullptr) - return args.GetReturnValue().Set(-1); + if (*needle_value == nullptr) return args.GetReturnValue().Set(-1); if (haystack_length < 2 || needle_value.length() < 1) { return args.GetReturnValue().Set(-1); @@ -885,8 +840,7 @@ void IndexOfString(const FunctionCallbackInfo& args) { const uint16_t* decoded_string = reinterpret_cast(decoder.out()); - if (decoded_string == nullptr) - return args.GetReturnValue().Set(-1); + if (decoded_string == nullptr) return args.GetReturnValue().Set(-1); result = SearchString(reinterpret_cast(haystack), haystack_length / 2, @@ -905,8 +859,7 @@ void IndexOfString(const FunctionCallbackInfo& args) { result *= 2; } else if (enc == UTF8) { String::Utf8Value needle_value(isolate, needle); - if (*needle_value == nullptr) - return args.GetReturnValue().Set(-1); + if (*needle_value == nullptr) return args.GetReturnValue().Set(-1); result = SearchString(reinterpret_cast(haystack), haystack_length, @@ -955,10 +908,8 @@ void IndexOfBuffer(const FunctionCallbackInfo& args) { const char* needle = needle_contents.data(); const size_t needle_length = needle_contents.length(); - int64_t opt_offset = IndexOfOffset(haystack_length, - offset_i64, - needle_length, - is_forward); + int64_t opt_offset = + IndexOfOffset(haystack_length, offset_i64, needle_length, is_forward); if (needle_length == 0) { // Match String#indexOf() and String#lastIndexOf() behavior. @@ -986,22 +937,20 @@ void IndexOfBuffer(const FunctionCallbackInfo& args) { if (haystack_length < 2 || needle_length < 2) { return args.GetReturnValue().Set(-1); } - result = SearchString( - reinterpret_cast(haystack), - haystack_length / 2, - reinterpret_cast(needle), - needle_length / 2, - offset / 2, - is_forward); + result = SearchString(reinterpret_cast(haystack), + haystack_length / 2, + reinterpret_cast(needle), + needle_length / 2, + offset / 2, + is_forward); result *= 2; } else { - result = SearchString( - reinterpret_cast(haystack), - haystack_length, - reinterpret_cast(needle), - needle_length, - offset, - is_forward); + result = SearchString(reinterpret_cast(haystack), + haystack_length, + reinterpret_cast(needle), + needle_length, + offset, + is_forward); } args.GetReturnValue().Set( @@ -1039,7 +988,6 @@ void IndexOfNumber(const FunctionCallbackInfo& args) { : -1); } - void Swap16(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -1048,7 +996,6 @@ void Swap16(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(args[0]); } - void Swap32(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -1057,7 +1004,6 @@ void Swap32(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(args[0]); } - void Swap64(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -1066,7 +1012,6 @@ void Swap64(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(args[0]); } - // Encode a single string to a UTF-8 Uint8Array (not Buffer). // Used in TextEncoder.prototype.encode. static void EncodeUtf8String(const FunctionCallbackInfo& args) { @@ -1087,7 +1032,6 @@ static void EncodeUtf8String(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(array); } - static void EncodeInto(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Isolate* isolate = env->isolate(); @@ -1121,7 +1065,6 @@ static void EncodeInto(const FunctionCallbackInfo& args) { results[1] = written; } - void SetBufferPrototype(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -1151,20 +1094,21 @@ void GetZeroFillToggle(const FunctionCallbackInfo& args) { ab = ArrayBuffer::New(env->isolate(), std::move(backing)); } - ab->SetPrivate( - env->context(), - env->untransferable_object_private_symbol(), - True(env->isolate())).Check(); + ab->SetPrivate(env->context(), + env->untransferable_object_private_symbol(), + True(env->isolate())) + .Check(); args.GetReturnValue().Set(Uint32Array::New(ab, 0, 1)); } -void BToA(const FunctionCallbackInfo& args) { +void AToB(const FunctionCallbackInfo& args) { CHECK(args[0]->IsString()); Environment* env = Environment::GetCurrent(args); Isolate* isolate = env->isolate(); Local input = args[0].As(); + // Check latin if (!input->IsOneByte()) { env->isolate()->ThrowException(ERR_INVALID_CHARACTER(env->isolate())); return; @@ -1172,37 +1116,42 @@ void BToA(const FunctionCallbackInfo& args) { node::Utf8Value input_utf8_value(isolate, input); - // Check latin std::string input_str = input_utf8_value.ToString(); - size_t max_dest_len = modp_b64_encode_len(input_str.length()) + 1; + size_t max_dest_len = base64_decoded_size_fast(input_str.length()); char* dest = static_cast(malloc(max_dest_len * sizeof(char))); - int dest_len = modp_b64_encode(dest, input_str.c_str(), input_str.length()); - - if (dest_len == -1) { + bool succ; + int dest_len = base64_decode(dest, + max_dest_len, + input_str.c_str(), + input_str.length(), + &succ, + true /* strict */); + + if (!succ) { free(dest); env->isolate()->ThrowException(ERR_INVALID_CHARACTER(env->isolate())); return; } - dest[dest_len] = 0; - MaybeLocal maybe_dest = String::NewFromUtf8( - isolate, - dest, - v8::NewStringType::kNormal, - dest_len); + MaybeLocal maybe_dest = + String::NewFromOneByte(isolate, + reinterpret_cast(dest), + v8::NewStringType::kNormal, + dest_len); CHECK(!maybe_dest.IsEmpty()); args.GetReturnValue().Set(maybe_dest.ToLocalChecked()); free(dest); } -void AToB(const FunctionCallbackInfo& args) { +void BToA(const FunctionCallbackInfo& args) { CHECK(args[0]->IsString()); Environment* env = Environment::GetCurrent(args); Isolate* isolate = env->isolate(); Local input = args[0].As(); + // Check latin if (!input->IsOneByte()) { env->isolate()->ThrowException(ERR_INVALID_CHARACTER(env->isolate())); return; @@ -1210,25 +1159,19 @@ void AToB(const FunctionCallbackInfo& args) { node::Utf8Value input_utf8_value(isolate, input); - // Check latin std::string input_str = input_utf8_value.ToString(); - size_t max_dest_len = modp_b64_decode_len(input_str.length()) + 1; + size_t max_dest_len = base64_encoded_size(input_str.length()); char* dest = static_cast(malloc(max_dest_len * sizeof(char))); - int dest_len = modp_b64_decode(dest, input_str.c_str(), input_str.length()); - if (dest_len == -1) { - free(dest); - env->isolate()->ThrowException(ERR_INVALID_CHARACTER(env->isolate())); - return; - } + int dest_len = + base64_encode(input_str.c_str(), input_str.length(), dest, max_dest_len); - dest[dest_len] = 0; - MaybeLocal maybe_dest = String::NewFromOneByte( - isolate, - reinterpret_cast(dest), - v8::NewStringType::kNormal, - dest_len); + MaybeLocal maybe_dest = + String::NewFromOneByte(isolate, + reinterpret_cast(dest), + v8::NewStringType::kNormal, + dest_len); CHECK(!maybe_dest.IsEmpty()); args.GetReturnValue().Set(maybe_dest.ToLocalChecked()); @@ -1260,13 +1203,17 @@ void Initialize(Local target, env->SetMethod(target, "encodeInto", EncodeInto); env->SetMethodNoSideEffect(target, "encodeUtf8String", EncodeUtf8String); - target->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "kMaxLength"), - Number::New(env->isolate(), kMaxLength)).Check(); - - target->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "kStringMaxLength"), - Integer::New(env->isolate(), String::kMaxLength)).Check(); + target + ->Set(env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "kMaxLength"), + Number::New(env->isolate(), kMaxLength)) + .Check(); + + target + ->Set(env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "kStringMaxLength"), + Integer::New(env->isolate(), String::kMaxLength)) + .Check(); env->SetMethodNoSideEffect(target, "asciiSlice", StringSlice); env->SetMethodNoSideEffect(target, "base64Slice", StringSlice); From ff1d1418d28c944be4bc5374f3d28a02b435a74f Mon Sep 17 00:00:00 2001 From: XadillaX Date: Wed, 28 Apr 2021 20:30:53 +0800 Subject: [PATCH 06/10] f --- benchmark/buffers/buffer-atob.js | 21 --------------------- benchmark/buffers/buffer-btoa.js | 21 --------------------- 2 files changed, 42 deletions(-) diff --git a/benchmark/buffers/buffer-atob.js b/benchmark/buffers/buffer-atob.js index ed8b6d96a3c38a..8a0b355bebbf1f 100644 --- a/benchmark/buffers/buffer-atob.js +++ b/benchmark/buffers/buffer-atob.js @@ -1,24 +1,3 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - 'use strict'; const buffer = require('buffer'); const common = require('../common.js'); diff --git a/benchmark/buffers/buffer-btoa.js b/benchmark/buffers/buffer-btoa.js index b0db9ca31c2631..5288cb6411a13a 100644 --- a/benchmark/buffers/buffer-btoa.js +++ b/benchmark/buffers/buffer-btoa.js @@ -1,24 +1,3 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - 'use strict'; const buffer = require('buffer'); const common = require('../common.js'); From 6b5eeec8617c14ab3b13edd3cf1838188a2ce403 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Wed, 28 Apr 2021 20:35:37 +0800 Subject: [PATCH 07/10] f --- deps/modp_b64/LICENSE | 33 --- deps/modp_b64/README.chromium | 17 -- deps/modp_b64/modp_b64.cc | 253 ------------------ deps/modp_b64/modp_b64.gyp | 13 - deps/modp_b64/modp_b64.h | 171 ------------ deps/modp_b64/modp_b64_data.h | 481 ---------------------------------- 6 files changed, 968 deletions(-) delete mode 100644 deps/modp_b64/LICENSE delete mode 100644 deps/modp_b64/README.chromium delete mode 100644 deps/modp_b64/modp_b64.cc delete mode 100644 deps/modp_b64/modp_b64.gyp delete mode 100644 deps/modp_b64/modp_b64.h delete mode 100644 deps/modp_b64/modp_b64_data.h diff --git a/deps/modp_b64/LICENSE b/deps/modp_b64/LICENSE deleted file mode 100644 index 55af76f3eb690d..00000000000000 --- a/deps/modp_b64/LICENSE +++ /dev/null @@ -1,33 +0,0 @@ - * MODP_B64 - High performance base64 encoder/decoder - * Version 1.3 -- 17-Mar-2006 - * http://modp.com/release/base64 - * - * Copyright (c) 2005, 2006 Nick Galbreath -- nickg [at] modp [dot] com - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of the modp.com nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/deps/modp_b64/README.chromium b/deps/modp_b64/README.chromium deleted file mode 100644 index 364a0507373f90..00000000000000 --- a/deps/modp_b64/README.chromium +++ /dev/null @@ -1,17 +0,0 @@ -Name: modp base64 decoder -Short Name: stringencoders -URL: https://github.com/client9/stringencoders -Version: unknown -License: BSD -Security Critical: yes - -Description: -The modp_b64.c file was modified to remove the inclusion of modp's config.h -and to fix compilation errors that occur under VC8. The file was renamed -modp_b64.cc to force it to be compiled as C++ so that the inclusion of -basictypes.h could be possible. - -The modp_b64.cc and modp_b64.h files were modified to make them safe on -64-bit systems. -The modp_b64.cc was modified to avoid misaligned read/write on -little-endian hardware. diff --git a/deps/modp_b64/modp_b64.cc b/deps/modp_b64/modp_b64.cc deleted file mode 100644 index fdb8a40ec7d28a..00000000000000 --- a/deps/modp_b64/modp_b64.cc +++ /dev/null @@ -1,253 +0,0 @@ -/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ -/* vi: set expandtab shiftwidth=4 tabstop=4: */ -/** - * \file - *
- * MODP_B64 - High performance base64 encoder/decoder
- * Version 1.3 -- 17-Mar-2006
- * http://modp.com/release/base64
- *
- * Copyright © 2005, 2006  Nick Galbreath -- nickg [at] modp [dot] com
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *   Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- *
- *   Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- *
- *   Neither the name of the modp.com nor the names of its
- *   contributors may be used to endorse or promote products derived from
- *   this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This is the standard "new" BSD license:
- * http://www.opensource.org/licenses/bsd-license.php
- * 
- */ - -/* public header */ -#include "modp_b64.h" - -/* - * If you are ripping this out of the library, comment out the next - * line and uncomment the next lines as approrpiate - */ -//#include "config.h" - -/* if on motoral, sun, ibm; uncomment this */ -/* #define WORDS_BIGENDIAN 1 */ -/* else for Intel, Amd; uncomment this */ -/* #undef WORDS_BIGENDIAN */ - -#include "modp_b64_data.h" - -#define BADCHAR 0x01FFFFFF - -/** - * you can control if we use padding by commenting out this - * next line. However, I highly recommend you use padding and not - * using it should only be for compatability with a 3rd party. - * Also, 'no padding' is not tested! - */ -#define DOPAD 1 - -/* - * if we aren't doing padding - * set the pad character to NULL - */ -#ifndef DOPAD -#undef CHARPAD -#define CHARPAD '\0' -#endif - -size_t modp_b64_encode(char* dest, const char* str, size_t len) -{ - size_t i = 0; - uint8_t* p = (uint8_t*) dest; - - /* unsigned here is important! */ - uint8_t t1, t2, t3; - - if (len > 2) { - for (; i < len - 2; i += 3) { - t1 = str[i]; t2 = str[i+1]; t3 = str[i+2]; - *p++ = e0[t1]; - *p++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)]; - *p++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)]; - *p++ = e2[t3]; - } - } - - switch (len - i) { - case 0: - break; - case 1: - t1 = str[i]; - *p++ = e0[t1]; - *p++ = e1[(t1 & 0x03) << 4]; - *p++ = CHARPAD; - *p++ = CHARPAD; - break; - default: /* case 2 */ - t1 = str[i]; t2 = str[i+1]; - *p++ = e0[t1]; - *p++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)]; - *p++ = e2[(t2 & 0x0F) << 2]; - *p++ = CHARPAD; - } - - *p = '\0'; - return p - (uint8_t*)dest; -} - -#ifdef WORDS_BIGENDIAN /* BIG ENDIAN -- SUN / IBM / MOTOROLA */ -int modp_b64_decode(char* dest, const char* src, int len) -{ - if (len == 0) return 0; - -#ifdef DOPAD - /* if padding is used, then the message must be at least - 4 chars and be a multiple of 4. - there can be at most 2 pad chars at the end */ - if (len < 4 || (len % 4 != 0)) return MODP_B64_ERROR; - if (src[len-1] == CHARPAD) { - len--; - if (src[len -1] == CHARPAD) { - len--; - } - } -#endif /* DOPAD */ - - size_t i; - int leftover = len % 4; - size_t chunks = (leftover == 0) ? len / 4 - 1 : len /4; - - uint8_t* p = (uint8_t*) dest; - uint32_t x = 0; - uint32_t* destInt = (uint32_t*) p; - uint32_t* srcInt = (uint32_t*) src; - uint32_t y = *srcInt++; - for (i = 0; i < chunks; ++i) { - x = d0[y >> 24 & 0xff] | d1[y >> 16 & 0xff] | - d2[y >> 8 & 0xff] | d3[y & 0xff]; - - if (x >= BADCHAR) return MODP_B64_ERROR; - *destInt = x << 8; - p += 3; - destInt = (uint32_t*)p; - y = *srcInt++; - } - - switch (leftover) { - case 0: - x = d0[y >> 24 & 0xff] | d1[y >> 16 & 0xff] | - d2[y >> 8 & 0xff] | d3[y & 0xff]; - if (x >= BADCHAR) return MODP_B64_ERROR; - *p++ = ((uint8_t*)&x)[1]; - *p++ = ((uint8_t*)&x)[2]; - *p = ((uint8_t*)&x)[3]; - return (chunks+1)*3; - case 1: - x = d3[y >> 24]; - *p = (uint8_t)x; - break; - case 2: - x = d3[y >> 24] *64 + d3[(y >> 16) & 0xff]; - *p = (uint8_t)(x >> 4); - break; - default: /* case 3 */ - x = (d3[y >> 24] *64 + d3[(y >> 16) & 0xff])*64 + - d3[(y >> 8) & 0xff]; - *p++ = (uint8_t) (x >> 10); - *p = (uint8_t) (x >> 2); - break; - } - - if (x >= BADCHAR) return MODP_B64_ERROR; - return 3*chunks + (6*leftover)/8; -} - -#else /* LITTLE ENDIAN -- INTEL AND FRIENDS */ - -size_t modp_b64_decode(char* dest, const char* src, size_t len) -{ - if (len == 0) return 0; - -#ifdef DOPAD - /* - * if padding is used, then the message must be at least - * 4 chars and be a multiple of 4 - */ - if (len < 4 || (len % 4 != 0)) return MODP_B64_ERROR; /* error */ - /* there can be at most 2 pad chars at the end */ - if (src[len-1] == CHARPAD) { - len--; - if (src[len -1] == CHARPAD) { - len--; - } - } -#endif - - size_t i; - int leftover = len % 4; - size_t chunks = (leftover == 0) ? len / 4 - 1 : len /4; - - uint8_t* p = (uint8_t*)dest; - uint32_t x = 0; - const uint8_t* y = (uint8_t*)src; - for (i = 0; i < chunks; ++i, y += 4) { - x = d0[y[0]] | d1[y[1]] | d2[y[2]] | d3[y[3]]; - if (x >= BADCHAR) return MODP_B64_ERROR; - *p++ = ((uint8_t*)(&x))[0]; - *p++ = ((uint8_t*)(&x))[1]; - *p++ = ((uint8_t*)(&x))[2]; - } - - switch (leftover) { - case 0: - x = d0[y[0]] | d1[y[1]] | d2[y[2]] | d3[y[3]]; - - if (x >= BADCHAR) return MODP_B64_ERROR; - *p++ = ((uint8_t*)(&x))[0]; - *p++ = ((uint8_t*)(&x))[1]; - *p = ((uint8_t*)(&x))[2]; - return (chunks+1)*3; - break; - case 1: /* with padding this is an impossible case */ - x = d0[y[0]]; - *p = *((uint8_t*)(&x)); // i.e. first char/byte in int - break; - case 2: // * case 2, 1 output byte */ - x = d0[y[0]] | d1[y[1]]; - *p = *((uint8_t*)(&x)); // i.e. first char - break; - default: /* case 3, 2 output bytes */ - x = d0[y[0]] | d1[y[1]] | d2[y[2]]; /* 0x3c */ - *p++ = ((uint8_t*)(&x))[0]; - *p = ((uint8_t*)(&x))[1]; - break; - } - - if (x >= BADCHAR) return MODP_B64_ERROR; - - return 3*chunks + (6*leftover)/8; -} - -#endif /* if bigendian / else / endif */ diff --git a/deps/modp_b64/modp_b64.gyp b/deps/modp_b64/modp_b64.gyp deleted file mode 100644 index 652aedfb067981..00000000000000 --- a/deps/modp_b64/modp_b64.gyp +++ /dev/null @@ -1,13 +0,0 @@ -{ - 'targets': [ - { - 'target_name': 'modp_b64', - 'type': 'static_library', - 'include_dirs': [ '.' ], - 'direct_dependent_settings': { - 'include_dirs': [ '.' ], - }, - 'sources': [ 'modp_b64.cc' ], - }, - ] -} diff --git a/deps/modp_b64/modp_b64.h b/deps/modp_b64/modp_b64.h deleted file mode 100644 index 074b901b5e7274..00000000000000 --- a/deps/modp_b64/modp_b64.h +++ /dev/null @@ -1,171 +0,0 @@ -/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */ -/* vi: set expandtab shiftwidth=4 tabstop=4: */ - -/** - * \file - *
- * High performance base64 encoder / decoder
- * Version 1.3 -- 17-Mar-2006
- *
- * Copyright © 2005, 2006, Nick Galbreath -- nickg [at] modp [dot] com
- * All rights reserved.
- *
- * http://modp.com/release/base64
- *
- * Released under bsd license.  See modp_b64.c for details.
- * 
- * - * The default implementation is the standard b64 encoding with padding. - * It's easy to change this to use "URL safe" characters and to remove - * padding. See the modp_b64.c source code for details. - * - */ - -#ifndef MODP_B64 -#define MODP_B64 - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Encode a raw binary string into base 64. - * src contains the bytes - * len contains the number of bytes in the src - * dest should be allocated by the caller to contain - * at least modp_b64_encode_len(len) bytes (see below) - * This will contain the null-terminated b64 encoded result - * returns length of the destination string plus the ending null byte - * i.e. the result will be equal to strlen(dest) + 1 - * - * Example - * - * \code - * char* src = ...; - * int srclen = ...; //the length of number of bytes in src - * char* dest = (char*) malloc(modp_b64_encode_len); - * int len = modp_b64_encode(dest, src, sourcelen); - * if (len == -1) { - * printf("Error\n"); - * } else { - * printf("b64 = %s\n", dest); - * } - * \endcode - * - */ -size_t modp_b64_encode(char* dest, const char* str, size_t len); - -/** - * Decode a base64 encoded string - * - * src should contain exactly len bytes of b64 characters. - * if src contains -any- non-base characters (such as white - * space, -1 is returned. - * - * dest should be allocated by the caller to contain at least - * len * 3 / 4 bytes. - * - * Returns the length (strlen) of the output, or -1 if unable to - * decode - * - * \code - * char* src = ...; - * int srclen = ...; // or if you don't know use strlen(src) - * char* dest = (char*) malloc(modp_b64_decode_len(srclen)); - * int len = modp_b64_decode(dest, src, sourcelen); - * if (len == -1) { error } - * \endcode - */ -size_t modp_b64_decode(char* dest, const char* src, size_t len); - -/** - * Given a source string of length len, this returns the amount of - * memory the destination string should have. - * - * remember, this is integer math - * 3 bytes turn into 4 chars - * ceiling[len / 3] * 4 + 1 - * - * +1 is for any extra null. - */ -#define modp_b64_encode_len(A) ((A+2)/3 * 4 + 1) - -/** - * Given a base64 string of length len, - * this returns the amount of memory required for output string - * It maybe be more than the actual number of bytes written. - * NOTE: remember this is integer math - * this allocates a bit more memory than traditional versions of b64 - * decode 4 chars turn into 3 bytes - * floor[len * 3/4] + 2 - */ -#define modp_b64_decode_len(A) (A / 4 * 3 + 2) - -/** - * Will return the strlen of the output from encoding. - * This may be less than the required number of bytes allocated. - * - * This allows you to 'deserialized' a struct - * \code - * char* b64encoded = "..."; - * int len = strlen(b64encoded); - * - * struct datastuff foo; - * if (modp_b64_encode_strlen(sizeof(struct datastuff)) != len) { - * // wrong size - * return false; - * } else { - * // safe to do; - * if (modp_b64_decode((char*) &foo, b64encoded, len) == -1) { - * // bad characters - * return false; - * } - * } - * // foo is filled out now - * \endcode - */ -#define modp_b64_encode_strlen(A) ((A + 2)/ 3 * 4) - -#define MODP_B64_ERROR ((size_t)-1) - -#ifdef __cplusplus -} - -#include - -inline std::string& modp_b64_encode(std::string& s) -{ - std::string x(modp_b64_encode_len(s.size()), '\0'); - size_t d = modp_b64_encode(const_cast(x.data()), s.data(), (int)s.size()); - x.erase(d, std::string::npos); - s.swap(x); - return s; -} - -/** - * base 64 decode a string (self-modifing) - * On failure, the string is empty. - * - * This function is for C++ only (duh) - * - * \param[in,out] s the string to be decoded - * \return a reference to the input string - */ -inline std::string& modp_b64_decode(std::string& s) -{ - std::string x(modp_b64_decode_len(s.size()), '\0'); - size_t d = modp_b64_decode(const_cast(x.data()), s.data(), (int)s.size()); - if (d == MODP_B64_ERROR) { - x.clear(); - } else { - x.erase(d, std::string::npos); - } - s.swap(x); - return s; -} - -#endif /* __cplusplus */ - -#endif /* MODP_B64 */ diff --git a/deps/modp_b64/modp_b64_data.h b/deps/modp_b64/modp_b64_data.h deleted file mode 100644 index 2ecf5977b9ec8c..00000000000000 --- a/deps/modp_b64/modp_b64_data.h +++ /dev/null @@ -1,481 +0,0 @@ -#include - -#define CHAR62 '+' -#define CHAR63 '/' -#define CHARPAD '=' -static const char e0[256] = { - 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'C', 'C', - 'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'E', - 'F', 'F', 'F', 'F', 'G', 'G', 'G', 'G', 'H', 'H', - 'H', 'H', 'I', 'I', 'I', 'I', 'J', 'J', 'J', 'J', - 'K', 'K', 'K', 'K', 'L', 'L', 'L', 'L', 'M', 'M', - 'M', 'M', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O', - 'P', 'P', 'P', 'P', 'Q', 'Q', 'Q', 'Q', 'R', 'R', - 'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T', - 'U', 'U', 'U', 'U', 'V', 'V', 'V', 'V', 'W', 'W', - 'W', 'W', 'X', 'X', 'X', 'X', 'Y', 'Y', 'Y', 'Y', - 'Z', 'Z', 'Z', 'Z', 'a', 'a', 'a', 'a', 'b', 'b', - 'b', 'b', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd', - 'e', 'e', 'e', 'e', 'f', 'f', 'f', 'f', 'g', 'g', - 'g', 'g', 'h', 'h', 'h', 'h', 'i', 'i', 'i', 'i', - 'j', 'j', 'j', 'j', 'k', 'k', 'k', 'k', 'l', 'l', - 'l', 'l', 'm', 'm', 'm', 'm', 'n', 'n', 'n', 'n', - 'o', 'o', 'o', 'o', 'p', 'p', 'p', 'p', 'q', 'q', - 'q', 'q', 'r', 'r', 'r', 'r', 's', 's', 's', 's', - 't', 't', 't', 't', 'u', 'u', 'u', 'u', 'v', 'v', - 'v', 'v', 'w', 'w', 'w', 'w', 'x', 'x', 'x', 'x', - 'y', 'y', 'y', 'y', 'z', 'z', 'z', 'z', '0', '0', - '0', '0', '1', '1', '1', '1', '2', '2', '2', '2', - '3', '3', '3', '3', '4', '4', '4', '4', '5', '5', - '5', '5', '6', '6', '6', '6', '7', '7', '7', '7', - '8', '8', '8', '8', '9', '9', '9', '9', '+', '+', - '+', '+', '/', '/', '/', '/' -}; - -static const char e1[256] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', - 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', - 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', - 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', - 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', - 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', - '4', '5', '6', '7', '8', '9', '+', '/', 'A', 'B', - 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', - 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', - 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', - 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', - 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', - 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', - 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', '+', '/' -}; - -static const char e2[256] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', - 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', - 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', - 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', - 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', - 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', - '4', '5', '6', '7', '8', '9', '+', '/', 'A', 'B', - 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', - 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', - 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', - 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', - 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', - 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', - 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', '+', '/' -}; - - - -#ifdef WORDS_BIGENDIAN - - -/* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */ - -static const uint32_t d0[256] = { -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x00f80000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00fc0000, -0x00d00000, 0x00d40000, 0x00d80000, 0x00dc0000, 0x00e00000, 0x00e40000, -0x00e80000, 0x00ec0000, 0x00f00000, 0x00f40000, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, -0x00040000, 0x00080000, 0x000c0000, 0x00100000, 0x00140000, 0x00180000, -0x001c0000, 0x00200000, 0x00240000, 0x00280000, 0x002c0000, 0x00300000, -0x00340000, 0x00380000, 0x003c0000, 0x00400000, 0x00440000, 0x00480000, -0x004c0000, 0x00500000, 0x00540000, 0x00580000, 0x005c0000, 0x00600000, -0x00640000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x00680000, 0x006c0000, 0x00700000, 0x00740000, 0x00780000, -0x007c0000, 0x00800000, 0x00840000, 0x00880000, 0x008c0000, 0x00900000, -0x00940000, 0x00980000, 0x009c0000, 0x00a00000, 0x00a40000, 0x00a80000, -0x00ac0000, 0x00b00000, 0x00b40000, 0x00b80000, 0x00bc0000, 0x00c00000, -0x00c40000, 0x00c80000, 0x00cc0000, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff -}; - - -static const uint32_t d1[256] = { -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x0003e000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0003f000, -0x00034000, 0x00035000, 0x00036000, 0x00037000, 0x00038000, 0x00039000, -0x0003a000, 0x0003b000, 0x0003c000, 0x0003d000, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, -0x00001000, 0x00002000, 0x00003000, 0x00004000, 0x00005000, 0x00006000, -0x00007000, 0x00008000, 0x00009000, 0x0000a000, 0x0000b000, 0x0000c000, -0x0000d000, 0x0000e000, 0x0000f000, 0x00010000, 0x00011000, 0x00012000, -0x00013000, 0x00014000, 0x00015000, 0x00016000, 0x00017000, 0x00018000, -0x00019000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x0001a000, 0x0001b000, 0x0001c000, 0x0001d000, 0x0001e000, -0x0001f000, 0x00020000, 0x00021000, 0x00022000, 0x00023000, 0x00024000, -0x00025000, 0x00026000, 0x00027000, 0x00028000, 0x00029000, 0x0002a000, -0x0002b000, 0x0002c000, 0x0002d000, 0x0002e000, 0x0002f000, 0x00030000, -0x00031000, 0x00032000, 0x00033000, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff -}; - - -static const uint32_t d2[256] = { -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x00000f80, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000fc0, -0x00000d00, 0x00000d40, 0x00000d80, 0x00000dc0, 0x00000e00, 0x00000e40, -0x00000e80, 0x00000ec0, 0x00000f00, 0x00000f40, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, -0x00000040, 0x00000080, 0x000000c0, 0x00000100, 0x00000140, 0x00000180, -0x000001c0, 0x00000200, 0x00000240, 0x00000280, 0x000002c0, 0x00000300, -0x00000340, 0x00000380, 0x000003c0, 0x00000400, 0x00000440, 0x00000480, -0x000004c0, 0x00000500, 0x00000540, 0x00000580, 0x000005c0, 0x00000600, -0x00000640, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x00000680, 0x000006c0, 0x00000700, 0x00000740, 0x00000780, -0x000007c0, 0x00000800, 0x00000840, 0x00000880, 0x000008c0, 0x00000900, -0x00000940, 0x00000980, 0x000009c0, 0x00000a00, 0x00000a40, 0x00000a80, -0x00000ac0, 0x00000b00, 0x00000b40, 0x00000b80, 0x00000bc0, 0x00000c00, -0x00000c40, 0x00000c80, 0x00000cc0, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff -}; - - -static const uint32_t d3[256] = { -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x0000003e, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0000003f, -0x00000034, 0x00000035, 0x00000036, 0x00000037, 0x00000038, 0x00000039, -0x0000003a, 0x0000003b, 0x0000003c, 0x0000003d, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, -0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, -0x00000007, 0x00000008, 0x00000009, 0x0000000a, 0x0000000b, 0x0000000c, -0x0000000d, 0x0000000e, 0x0000000f, 0x00000010, 0x00000011, 0x00000012, -0x00000013, 0x00000014, 0x00000015, 0x00000016, 0x00000017, 0x00000018, -0x00000019, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x0000001a, 0x0000001b, 0x0000001c, 0x0000001d, 0x0000001e, -0x0000001f, 0x00000020, 0x00000021, 0x00000022, 0x00000023, 0x00000024, -0x00000025, 0x00000026, 0x00000027, 0x00000028, 0x00000029, 0x0000002a, -0x0000002b, 0x0000002c, 0x0000002d, 0x0000002e, 0x0000002f, 0x00000030, -0x00000031, 0x00000032, 0x00000033, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff -}; - - -#else - - -/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */ - -static const uint32_t d0[256] = { -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x000000f8, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x000000fc, -0x000000d0, 0x000000d4, 0x000000d8, 0x000000dc, 0x000000e0, 0x000000e4, -0x000000e8, 0x000000ec, 0x000000f0, 0x000000f4, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, -0x00000004, 0x00000008, 0x0000000c, 0x00000010, 0x00000014, 0x00000018, -0x0000001c, 0x00000020, 0x00000024, 0x00000028, 0x0000002c, 0x00000030, -0x00000034, 0x00000038, 0x0000003c, 0x00000040, 0x00000044, 0x00000048, -0x0000004c, 0x00000050, 0x00000054, 0x00000058, 0x0000005c, 0x00000060, -0x00000064, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x00000068, 0x0000006c, 0x00000070, 0x00000074, 0x00000078, -0x0000007c, 0x00000080, 0x00000084, 0x00000088, 0x0000008c, 0x00000090, -0x00000094, 0x00000098, 0x0000009c, 0x000000a0, 0x000000a4, 0x000000a8, -0x000000ac, 0x000000b0, 0x000000b4, 0x000000b8, 0x000000bc, 0x000000c0, -0x000000c4, 0x000000c8, 0x000000cc, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff -}; - - -static const uint32_t d1[256] = { -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x0000e003, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0000f003, -0x00004003, 0x00005003, 0x00006003, 0x00007003, 0x00008003, 0x00009003, -0x0000a003, 0x0000b003, 0x0000c003, 0x0000d003, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, -0x00001000, 0x00002000, 0x00003000, 0x00004000, 0x00005000, 0x00006000, -0x00007000, 0x00008000, 0x00009000, 0x0000a000, 0x0000b000, 0x0000c000, -0x0000d000, 0x0000e000, 0x0000f000, 0x00000001, 0x00001001, 0x00002001, -0x00003001, 0x00004001, 0x00005001, 0x00006001, 0x00007001, 0x00008001, -0x00009001, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x0000a001, 0x0000b001, 0x0000c001, 0x0000d001, 0x0000e001, -0x0000f001, 0x00000002, 0x00001002, 0x00002002, 0x00003002, 0x00004002, -0x00005002, 0x00006002, 0x00007002, 0x00008002, 0x00009002, 0x0000a002, -0x0000b002, 0x0000c002, 0x0000d002, 0x0000e002, 0x0000f002, 0x00000003, -0x00001003, 0x00002003, 0x00003003, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff -}; - - -static const uint32_t d2[256] = { -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x00800f00, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00c00f00, -0x00000d00, 0x00400d00, 0x00800d00, 0x00c00d00, 0x00000e00, 0x00400e00, -0x00800e00, 0x00c00e00, 0x00000f00, 0x00400f00, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, -0x00400000, 0x00800000, 0x00c00000, 0x00000100, 0x00400100, 0x00800100, -0x00c00100, 0x00000200, 0x00400200, 0x00800200, 0x00c00200, 0x00000300, -0x00400300, 0x00800300, 0x00c00300, 0x00000400, 0x00400400, 0x00800400, -0x00c00400, 0x00000500, 0x00400500, 0x00800500, 0x00c00500, 0x00000600, -0x00400600, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x00800600, 0x00c00600, 0x00000700, 0x00400700, 0x00800700, -0x00c00700, 0x00000800, 0x00400800, 0x00800800, 0x00c00800, 0x00000900, -0x00400900, 0x00800900, 0x00c00900, 0x00000a00, 0x00400a00, 0x00800a00, -0x00c00a00, 0x00000b00, 0x00400b00, 0x00800b00, 0x00c00b00, 0x00000c00, -0x00400c00, 0x00800c00, 0x00c00c00, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff -}; - - -static const uint32_t d3[256] = { -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x003e0000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x003f0000, -0x00340000, 0x00350000, 0x00360000, 0x00370000, 0x00380000, 0x00390000, -0x003a0000, 0x003b0000, 0x003c0000, 0x003d0000, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000, -0x00010000, 0x00020000, 0x00030000, 0x00040000, 0x00050000, 0x00060000, -0x00070000, 0x00080000, 0x00090000, 0x000a0000, 0x000b0000, 0x000c0000, -0x000d0000, 0x000e0000, 0x000f0000, 0x00100000, 0x00110000, 0x00120000, -0x00130000, 0x00140000, 0x00150000, 0x00160000, 0x00170000, 0x00180000, -0x00190000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x001a0000, 0x001b0000, 0x001c0000, 0x001d0000, 0x001e0000, -0x001f0000, 0x00200000, 0x00210000, 0x00220000, 0x00230000, 0x00240000, -0x00250000, 0x00260000, 0x00270000, 0x00280000, 0x00290000, 0x002a0000, -0x002b0000, 0x002c0000, 0x002d0000, 0x002e0000, 0x002f0000, 0x00300000, -0x00310000, 0x00320000, 0x00330000, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, -0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff -}; - - -#endif From ba56cb9f7303ab134c8af283212ade6b2e06f4d7 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Wed, 28 Apr 2021 20:44:04 +0800 Subject: [PATCH 08/10] f --- src/base64-inl.h | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/base64-inl.h b/src/base64-inl.h index c57ccf672a3245..3217ce092fb9e2 100644 --- a/src/base64-inl.h +++ b/src/base64-inl.h @@ -10,14 +10,17 @@ namespace node { extern const int8_t unbase64_table[256]; + inline static int8_t unbase64(uint8_t x) { return unbase64_table[x]; } + inline uint32_t ReadUint32BE(const unsigned char* p) { return static_cast(p[0] << 24U) | static_cast(p[1] << 16U) | - static_cast(p[2] << 8U) | static_cast(p[3]); + static_cast(p[2] << 8U) | + static_cast(p[3]); } #ifdef _MSC_VER @@ -27,12 +30,9 @@ inline uint32_t ReadUint32BE(const unsigned char* p) { #endif template -bool base64_decode_group_slow(char* const dst, - const size_t dstlen, - const TypeName* const src, - const size_t srclen, - size_t* const i, - size_t* const k) { +bool base64_decode_group_slow(char* const dst, const size_t dstlen, + const TypeName* const src, const size_t srclen, + size_t* const i, size_t* const k) { uint8_t hi; uint8_t lo; #define V(expr) \ @@ -100,7 +100,7 @@ size_t base64_decode_fast(char* const dst, } else { dst[k + 0] = ((v >> 22) & 0xFC) | ((v >> 20) & 0x03); dst[k + 1] = ((v >> 12) & 0xF0) | ((v >> 10) & 0x0F); - dst[k + 2] = ((v >> 2) & 0xC0) | ((v >> 0) & 0x3F); + dst[k + 2] = ((v >> 2) & 0xC0) | ((v >> 0) & 0x3F); i += 4; k += 3; } @@ -152,18 +152,22 @@ size_t base64_decode_fast(char* const dst, return k; } + template size_t base64_decoded_size(const TypeName* src, size_t size) { // 1-byte input cannot be decoded - if (size < 2) return 0; + if (size < 2) + return 0; if (src[size - 1] == '=') { size--; - if (src[size - 1] == '=') size--; + if (src[size - 1] == '=') + size--; } return base64_decoded_size_fast(size); } + template size_t base64_decode(char* const dst, const size_t dstlen, @@ -176,8 +180,12 @@ size_t base64_decode(char* const dst, dst, dstlen, src, srclen, decoded_size, succ, strict); } -inline size_t base64_encode( - const char* src, size_t slen, char* dst, size_t dlen, Base64Mode mode) { + +inline size_t base64_encode(const char* src, + size_t slen, + char* dst, + size_t dlen, + Base64Mode mode) { // We know how much we'll write, just make sure that there's space. CHECK(dlen >= base64_encoded_size(slen, mode) && "not enough space provided for base64 encode"); @@ -227,7 +235,8 @@ inline size_t base64_encode( dst[k + 0] = table[a >> 2]; dst[k + 1] = table[((a & 3) << 4) | (b >> 4)]; dst[k + 2] = table[(b & 0x0f) << 2]; - if (mode == Base64Mode::NORMAL) dst[k + 3] = '='; + if (mode == Base64Mode::NORMAL) + dst[k + 3] = '='; break; } @@ -237,4 +246,5 @@ inline size_t base64_encode( } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + #endif // SRC_BASE64_INL_H_ From 520019684b3105abf478b337cc82bee5ee2da2a0 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Wed, 28 Apr 2021 20:47:01 +0800 Subject: [PATCH 09/10] f --- src/base64-inl.h | 3 ++- src/base64.h | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/base64-inl.h b/src/base64-inl.h index 3217ce092fb9e2..38daccb3ff1c23 100644 --- a/src/base64-inl.h +++ b/src/base64-inl.h @@ -95,7 +95,8 @@ size_t base64_decode_fast(char* const dst, *succ = false; return 0; } - if (!base64_decode_group_slow(dst, dstlen, src, srclen, &i, &k)) return k; + if (!base64_decode_group_slow(dst, dstlen, src, srclen, &i, &k)) + return k; max_i = i + (srclen - i) / 4 * 4; // Align max_i again. } else { dst[k + 0] = ((v >> 22) & 0xFC) | ((v >> 20) & 0x03); diff --git a/src/base64.h b/src/base64.h index 8ea92f105b188f..c8578ffbe5614d 100644 --- a/src/base64.h +++ b/src/base64.h @@ -12,7 +12,10 @@ namespace node { //// Base 64 //// -enum class Base64Mode { NORMAL, URL }; +enum class Base64Mode { + NORMAL, + URL +}; static constexpr char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" @@ -24,17 +27,15 @@ static constexpr char base64_table_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" static inline const char* base64_select_table(Base64Mode mode) { switch (mode) { - case Base64Mode::NORMAL: - return base64_table; - case Base64Mode::URL: - return base64_table_url; - default: - UNREACHABLE(); + case Base64Mode::NORMAL: return base64_table; + case Base64Mode::URL: return base64_table_url; + default: UNREACHABLE(); } } static inline constexpr size_t base64_encoded_size( - size_t size, Base64Mode mode = Base64Mode::NORMAL) { + size_t size, + Base64Mode mode = Base64Mode::NORMAL) { return mode == Base64Mode::NORMAL ? ((size + 2) / 3 * 4) : static_cast(std::ceil( static_cast(size * 4) / 3)); @@ -66,5 +67,7 @@ inline size_t base64_encode(const char* src, Base64Mode mode = Base64Mode::NORMAL); } // namespace node + #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + #endif // SRC_BASE64_H_ From 074c82c34279608a9af52ae1832ffd027d2058d8 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Wed, 28 Apr 2021 20:49:39 +0800 Subject: [PATCH 10/10] f --- src/node_buffer.cc | 258 +++++++++++++++++++++++++++------------------ 1 file changed, 155 insertions(+), 103 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index c464eb9638b229..71a824d543716c 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -27,25 +27,24 @@ #include "node_external_reference.h" #include "node_internals.h" -#include "base64-inl.h" #include "env-inl.h" #include "string_bytes.h" #include "string_search.h" #include "util-inl.h" #include "v8.h" -#include #include +#include -#define THROW_AND_RETURN_UNLESS_BUFFER(env, obj) \ - THROW_AND_RETURN_IF_NOT_BUFFER(env, obj, "argument") +#define THROW_AND_RETURN_UNLESS_BUFFER(env, obj) \ + THROW_AND_RETURN_IF_NOT_BUFFER(env, obj, "argument") \ -#define THROW_AND_RETURN_IF_OOB(r) \ - do { \ - if ((r).IsNothing()) return; \ - if (!(r).FromJust()) \ - return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \ - } while (0) +#define THROW_AND_RETURN_IF_OOB(r) \ + do { \ + if ((r).IsNothing()) return; \ + if (!(r).FromJust()) \ + return node::THROW_ERR_OUT_OF_RANGE(env, "Index out of range"); \ + } while (0) \ namespace node { namespace Buffer { @@ -104,22 +103,21 @@ class CallbackInfo { Environment* const env_; }; -Local CallbackInfo::CreateTrackedArrayBuffer(Environment* env, - char* data, - size_t length, - FreeCallback callback, - void* hint) { + +Local CallbackInfo::CreateTrackedArrayBuffer( + Environment* env, + char* data, + size_t length, + FreeCallback callback, + void* hint) { CHECK_NOT_NULL(callback); CHECK_IMPLIES(data == nullptr, length == 0); CallbackInfo* self = new CallbackInfo(env, callback, data, hint); - std::unique_ptr bs = ArrayBuffer::NewBackingStore( - data, - length, - [](void*, size_t, void* arg) { + std::unique_ptr bs = + ArrayBuffer::NewBackingStore(data, length, [](void*, size_t, void* arg) { static_cast(arg)->OnBackingStoreFree(); - }, - self); + }, self); Local ab = ArrayBuffer::New(env->isolate(), std::move(bs)); // V8 simply ignores the BackingStore deleter callback if data == nullptr, @@ -136,11 +134,15 @@ Local CallbackInfo::CreateTrackedArrayBuffer(Environment* env, return ab; } + CallbackInfo::CallbackInfo(Environment* env, FreeCallback callback, char* data, void* hint) - : callback_(callback), data_(data), hint_(hint), env_(env) { + : callback_(callback), + data_(data), + hint_(hint), + env_(env) { env->AddCleanupHook(CleanupHook, this); env->isolate()->AdjustAmountOfExternalAllocatedMemory(sizeof(*this)); } @@ -181,7 +183,7 @@ void CallbackInfo::CallAndResetCallback() { void CallbackInfo::OnBackingStoreFree() { // This method should always release the memory for `this`. - std::unique_ptr self{this}; + std::unique_ptr self { this }; Mutex::ScopedLock lock(mutex_); // If callback_ == nullptr, that means that the callback has already run from // the cleanup hook, and there is nothing left to do here besides to clean @@ -196,6 +198,7 @@ void CallbackInfo::OnBackingStoreFree() { }); } + // Parse index for external array data. An empty Maybe indicates // a pending exception. `false` indicates that the index is out-of-bounds. inline MUST_USE_RESULT Maybe ParseArrayIndex(Environment* env, @@ -208,14 +211,17 @@ inline MUST_USE_RESULT Maybe ParseArrayIndex(Environment* env, } int64_t tmp_i; - if (!arg->IntegerValue(env->context()).To(&tmp_i)) return Nothing(); + if (!arg->IntegerValue(env->context()).To(&tmp_i)) + return Nothing(); - if (tmp_i < 0) return Just(false); + if (tmp_i < 0) + return Just(false); // Check that the result fits in a size_t. const uint64_t kSizeMax = static_cast(static_cast(-1)); // coverity[pointless_expression] - if (static_cast(tmp_i) > kSizeMax) return Just(false); + if (static_cast(tmp_i) > kSizeMax) + return Just(false); *ret = static_cast(tmp_i); return Just(true); @@ -229,33 +235,39 @@ bool HasInstance(Local val) { return val->IsArrayBufferView(); } + bool HasInstance(Local obj) { return obj->IsArrayBufferView(); } + char* Data(Local val) { CHECK(val->IsArrayBufferView()); Local ui = val.As(); return static_cast(ui->Buffer()->GetBackingStore()->Data()) + - ui->ByteOffset(); + ui->ByteOffset(); } + char* Data(Local obj) { return Data(obj.As()); } + size_t Length(Local val) { CHECK(val->IsArrayBufferView()); Local ui = val.As(); return ui->ByteLength(); } + size_t Length(Local obj) { CHECK(obj->IsArrayBufferView()); Local ui = obj.As(); return ui->ByteLength(); } + MaybeLocal New(Environment* env, Local ab, size_t byte_offset, @@ -264,7 +276,8 @@ MaybeLocal New(Environment* env, Local ui = Uint8Array::New(ab, byte_offset, length); Maybe mb = ui->SetPrototype(env->context(), env->buffer_prototype_object()); - if (mb.IsNothing()) return MaybeLocal(); + if (mb.IsNothing()) + return MaybeLocal(); return ui; } @@ -280,6 +293,7 @@ MaybeLocal New(Isolate* isolate, return New(env, ab, byte_offset, length); } + MaybeLocal New(Isolate* isolate, Local string, enum encoding enc) { @@ -300,7 +314,11 @@ MaybeLocal New(Isolate* isolate, } actual = StringBytes::Write( - isolate, static_cast(store->Data()), length, string, enc); + isolate, + static_cast(store->Data()), + length, + string, + enc); CHECK(actual <= length); if (LIKELY(actual > 0)) { @@ -317,6 +335,7 @@ MaybeLocal New(Isolate* isolate, return scope.EscapeMaybe(New(isolate, 0)); } + MaybeLocal New(Isolate* isolate, size_t length) { EscapableHandleScope handle_scope(isolate); Local obj; @@ -325,10 +344,12 @@ MaybeLocal New(Isolate* isolate, size_t length) { THROW_ERR_BUFFER_CONTEXT_NOT_AVAILABLE(isolate); return MaybeLocal(); } - if (Buffer::New(env, length).ToLocal(&obj)) return handle_scope.Escape(obj); + if (Buffer::New(env, length).ToLocal(&obj)) + return handle_scope.Escape(obj); return Local(); } + MaybeLocal New(Environment* env, size_t length) { EscapableHandleScope scope(env->isolate()); @@ -342,6 +363,7 @@ MaybeLocal New(Environment* env, size_t length) { AllocatedBuffer::AllocateManaged(env, length).ToBuffer()); } + MaybeLocal Copy(Isolate* isolate, const char* data, size_t length) { EscapableHandleScope handle_scope(isolate); Environment* env = Environment::GetCurrent(isolate); @@ -355,6 +377,7 @@ MaybeLocal Copy(Isolate* isolate, const char* data, size_t length) { return Local(); } + MaybeLocal Copy(Environment* env, const char* data, size_t length) { EscapableHandleScope scope(env->isolate()); @@ -372,6 +395,7 @@ MaybeLocal Copy(Environment* env, const char* data, size_t length) { return scope.EscapeMaybe(ret.ToBuffer()); } + MaybeLocal New(Isolate* isolate, char* data, size_t length, @@ -388,6 +412,7 @@ MaybeLocal New(Isolate* isolate, Buffer::New(env, data, length, callback, hint)); } + MaybeLocal New(Environment* env, char* data, size_t length, @@ -405,14 +430,14 @@ MaybeLocal New(Environment* env, CallbackInfo::CreateTrackedArrayBuffer(env, data, length, callback, hint); if (ab->SetPrivate(env->context(), env->untransferable_object_private_symbol(), - True(env->isolate())) - .IsNothing()) { + True(env->isolate())).IsNothing()) { return Local(); } MaybeLocal maybe_ui = Buffer::New(env, ab, 0, length); Local ui; - if (!maybe_ui.ToLocal(&ui)) return MaybeLocal(); + if (!maybe_ui.ToLocal(&ui)) + return MaybeLocal(); return scope.Escape(ui); } @@ -435,7 +460,9 @@ MaybeLocal New(Isolate* isolate, char* data, size_t length) { // The contract for this function is that `data` is allocated with malloc() // and not necessarily isolate's ArrayBuffer::Allocator. -MaybeLocal New(Environment* env, char* data, size_t length) { +MaybeLocal New(Environment* env, + char* data, + size_t length) { if (length > 0) { CHECK_NOT_NULL(data); CHECK(length <= kMaxLength); @@ -457,6 +484,7 @@ void CreateFromString(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(buf); } + template void StringSlice(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -465,7 +493,8 @@ void StringSlice(const FunctionCallbackInfo& args) { THROW_AND_RETURN_UNLESS_BUFFER(env, args.This()); ArrayBufferViewContents buffer(args.This()); - if (buffer.length() == 0) return args.GetReturnValue().SetEmptyString(); + if (buffer.length() == 0) + return args.GetReturnValue().SetEmptyString(); size_t start = 0; size_t end = 0; @@ -476,8 +505,12 @@ void StringSlice(const FunctionCallbackInfo& args) { size_t length = end - start; Local error; - MaybeLocal maybe_ret = StringBytes::Encode( - isolate, buffer.data() + start, length, encoding, &error); + MaybeLocal maybe_ret = + StringBytes::Encode(isolate, + buffer.data() + start, + length, + encoding, + &error); Local ret; if (!maybe_ret.ToLocal(&ret)) { CHECK(!error.IsEmpty()); @@ -487,8 +520,9 @@ void StringSlice(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(ret); } + // bytesCopied = copy(buffer, target[, targetStart][, sourceStart][, sourceEnd]) -void Copy(const FunctionCallbackInfo& args) { +void Copy(const FunctionCallbackInfo &args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -503,8 +537,8 @@ void Copy(const FunctionCallbackInfo& args) { THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], 0, &target_start)); THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[3], 0, &source_start)); - THROW_AND_RETURN_IF_OOB( - ParseArrayIndex(env, args[4], source.length(), &source_end)); + THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[4], source.length(), + &source_end)); // Copy 0 bytes; we're done if (target_start >= target_length || source_start >= source_end) @@ -525,6 +559,7 @@ void Copy(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(to_copy); } + void Fill(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Local ctx = env->context(); @@ -596,14 +631,16 @@ void Fill(const FunctionCallbackInfo& args) { start_fill: - if (str_length >= fill_length) return; + if (str_length >= fill_length) + return; // If str_length is zero, then either an empty buffer was provided, or Write() // indicated that no bytes could be written. If no bytes could be written, // then return -1 because the fill value is invalid. This will trigger a throw // in JavaScript. Silently failing should be avoided because it can lead to // buffers with unexpected contents. - if (str_length == 0) return args.GetReturnValue().Set(-1); + if (str_length == 0) + return args.GetReturnValue().Set(-1); size_t in_there = str_length; char* ptr = ts_obj_data + start + str_length; @@ -619,6 +656,7 @@ void Fill(const FunctionCallbackInfo& args) { } } + template void StringWrite(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -639,19 +677,24 @@ void StringWrite(const FunctionCallbackInfo& args) { env, "\"offset\" is outside of buffer bounds"); } - THROW_AND_RETURN_IF_OOB( - ParseArrayIndex(env, args[2], ts_obj_length - offset, &max_length)); + THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], ts_obj_length - offset, + &max_length)); max_length = std::min(ts_obj_length - offset, max_length); - if (max_length == 0) return args.GetReturnValue().Set(0); + if (max_length == 0) + return args.GetReturnValue().Set(0); - uint32_t written = StringBytes::Write( - env->isolate(), ts_obj_data + offset, max_length, str, encoding, nullptr); + uint32_t written = StringBytes::Write(env->isolate(), + ts_obj_data + offset, + max_length, + str, + encoding, + nullptr); args.GetReturnValue().Set(written); } -void ByteLengthUtf8(const FunctionCallbackInfo& args) { +void ByteLengthUtf8(const FunctionCallbackInfo &args) { Environment* env = Environment::GetCurrent(args); CHECK(args[0]->IsString()); @@ -676,7 +719,7 @@ static int normalizeCompareVal(int val, size_t a_length, size_t b_length) { return val; } -void CompareOffset(const FunctionCallbackInfo& args) { +void CompareOffset(const FunctionCallbackInfo &args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -691,10 +734,10 @@ void CompareOffset(const FunctionCallbackInfo& args) { THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[2], 0, &target_start)); THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[3], 0, &source_start)); - THROW_AND_RETURN_IF_OOB( - ParseArrayIndex(env, args[4], target.length(), &target_end)); - THROW_AND_RETURN_IF_OOB( - ParseArrayIndex(env, args[5], source.length(), &source_end)); + THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[4], target.length(), + &target_end)); + THROW_AND_RETURN_IF_OOB(ParseArrayIndex(env, args[5], source.length(), + &source_end)); if (source_start > source.length()) return THROW_ERR_OUT_OF_RANGE( @@ -710,18 +753,17 @@ void CompareOffset(const FunctionCallbackInfo& args) { std::min(std::min(source_end - source_start, target_end - target_start), source.length() - source_start); - int val = - normalizeCompareVal(to_cmp > 0 ? memcmp(source.data() + source_start, - target.data() + target_start, - to_cmp) - : 0, - source_end - source_start, - target_end - target_start); + int val = normalizeCompareVal(to_cmp > 0 ? + memcmp(source.data() + source_start, + target.data() + target_start, + to_cmp) : 0, + source_end - source_start, + target_end - target_start); args.GetReturnValue().Set(val); } -void Compare(const FunctionCallbackInfo& args) { +void Compare(const FunctionCallbackInfo &args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -731,13 +773,13 @@ void Compare(const FunctionCallbackInfo& args) { size_t cmp_length = std::min(a.length(), b.length()); - int val = normalizeCompareVal( - cmp_length > 0 ? memcmp(a.data(), b.data(), cmp_length) : 0, - a.length(), - b.length()); + int val = normalizeCompareVal(cmp_length > 0 ? + memcmp(a.data(), b.data(), cmp_length) : 0, + a.length(), b.length()); args.GetReturnValue().Set(val); } + // Computes the offset for starting an indexOf or lastIndexOf search. // Returns either a valid offset in [0...], ie inside the Buffer, // or -1 to signal that there is no possible match. @@ -794,15 +836,16 @@ void IndexOfString(const FunctionCallbackInfo& args) { const char* haystack = buffer.data(); // Round down to the nearest multiple of 2 in case of UCS2. - const size_t haystack_length = - (enc == UCS2) ? buffer.length() & ~1 - : buffer.length(); // NOLINT(whitespace/operators) + const size_t haystack_length = (enc == UCS2) ? + buffer.length() &~ 1 : buffer.length(); // NOLINT(whitespace/operators) size_t needle_length; if (!StringBytes::Size(isolate, needle, enc).To(&needle_length)) return; - int64_t opt_offset = - IndexOfOffset(haystack_length, offset_i64, needle_length, is_forward); + int64_t opt_offset = IndexOfOffset(haystack_length, + offset_i64, + needle_length, + is_forward); if (needle_length == 0) { // Match String#indexOf() and String#lastIndexOf() behavior. @@ -828,7 +871,8 @@ void IndexOfString(const FunctionCallbackInfo& args) { if (enc == UCS2) { String::Value needle_value(isolate, needle); - if (*needle_value == nullptr) return args.GetReturnValue().Set(-1); + if (*needle_value == nullptr) + return args.GetReturnValue().Set(-1); if (haystack_length < 2 || needle_value.length() < 1) { return args.GetReturnValue().Set(-1); @@ -840,7 +884,8 @@ void IndexOfString(const FunctionCallbackInfo& args) { const uint16_t* decoded_string = reinterpret_cast(decoder.out()); - if (decoded_string == nullptr) return args.GetReturnValue().Set(-1); + if (decoded_string == nullptr) + return args.GetReturnValue().Set(-1); result = SearchString(reinterpret_cast(haystack), haystack_length / 2, @@ -859,7 +904,8 @@ void IndexOfString(const FunctionCallbackInfo& args) { result *= 2; } else if (enc == UTF8) { String::Utf8Value needle_value(isolate, needle); - if (*needle_value == nullptr) return args.GetReturnValue().Set(-1); + if (*needle_value == nullptr) + return args.GetReturnValue().Set(-1); result = SearchString(reinterpret_cast(haystack), haystack_length, @@ -908,8 +954,10 @@ void IndexOfBuffer(const FunctionCallbackInfo& args) { const char* needle = needle_contents.data(); const size_t needle_length = needle_contents.length(); - int64_t opt_offset = - IndexOfOffset(haystack_length, offset_i64, needle_length, is_forward); + int64_t opt_offset = IndexOfOffset(haystack_length, + offset_i64, + needle_length, + is_forward); if (needle_length == 0) { // Match String#indexOf() and String#lastIndexOf() behavior. @@ -937,20 +985,22 @@ void IndexOfBuffer(const FunctionCallbackInfo& args) { if (haystack_length < 2 || needle_length < 2) { return args.GetReturnValue().Set(-1); } - result = SearchString(reinterpret_cast(haystack), - haystack_length / 2, - reinterpret_cast(needle), - needle_length / 2, - offset / 2, - is_forward); + result = SearchString( + reinterpret_cast(haystack), + haystack_length / 2, + reinterpret_cast(needle), + needle_length / 2, + offset / 2, + is_forward); result *= 2; } else { - result = SearchString(reinterpret_cast(haystack), - haystack_length, - reinterpret_cast(needle), - needle_length, - offset, - is_forward); + result = SearchString( + reinterpret_cast(haystack), + haystack_length, + reinterpret_cast(needle), + needle_length, + offset, + is_forward); } args.GetReturnValue().Set( @@ -988,6 +1038,7 @@ void IndexOfNumber(const FunctionCallbackInfo& args) { : -1); } + void Swap16(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -996,6 +1047,7 @@ void Swap16(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(args[0]); } + void Swap32(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -1004,6 +1056,7 @@ void Swap32(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(args[0]); } + void Swap64(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); @@ -1012,6 +1065,7 @@ void Swap64(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(args[0]); } + // Encode a single string to a UTF-8 Uint8Array (not Buffer). // Used in TextEncoder.prototype.encode. static void EncodeUtf8String(const FunctionCallbackInfo& args) { @@ -1032,6 +1086,7 @@ static void EncodeUtf8String(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(array); } + static void EncodeInto(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Isolate* isolate = env->isolate(); @@ -1065,6 +1120,7 @@ static void EncodeInto(const FunctionCallbackInfo& args) { results[1] = written; } + void SetBufferPrototype(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -1094,10 +1150,10 @@ void GetZeroFillToggle(const FunctionCallbackInfo& args) { ab = ArrayBuffer::New(env->isolate(), std::move(backing)); } - ab->SetPrivate(env->context(), - env->untransferable_object_private_symbol(), - True(env->isolate())) - .Check(); + ab->SetPrivate( + env->context(), + env->untransferable_object_private_symbol(), + True(env->isolate())).Check(); args.GetReturnValue().Set(Uint32Array::New(ab, 0, 1)); } @@ -1203,17 +1259,13 @@ void Initialize(Local target, env->SetMethod(target, "encodeInto", EncodeInto); env->SetMethodNoSideEffect(target, "encodeUtf8String", EncodeUtf8String); - target - ->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "kMaxLength"), - Number::New(env->isolate(), kMaxLength)) - .Check(); + target->Set(env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "kMaxLength"), + Number::New(env->isolate(), kMaxLength)).Check(); - target - ->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "kStringMaxLength"), - Integer::New(env->isolate(), String::kMaxLength)) - .Check(); + target->Set(env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "kStringMaxLength"), + Integer::New(env->isolate(), String::kMaxLength)).Check(); env->SetMethodNoSideEffect(target, "asciiSlice", StringSlice); env->SetMethodNoSideEffect(target, "base64Slice", StringSlice); @@ -1233,8 +1285,8 @@ void Initialize(Local target, env->SetMethod(target, "getZeroFillToggle", GetZeroFillToggle); - env->SetMethod(target, "btoa", BToA); env->SetMethod(target, "atob", AToB); + env->SetMethod(target, "btoa", BToA); Blob::Initialize(env, target); } @@ -1278,8 +1330,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(StringWrite); registry->Register(GetZeroFillToggle); - registry->Register(BToA); registry->Register(AToB); + registry->Register(BToA); Blob::RegisterExternalReferences(registry); FixedSizeBlobCopyJob::RegisterExternalReferences(registry);