Skip to content

Commit 9916d93

Browse files
committed
Fixed shields image
1 parent d4f8024 commit 9916d93

8 files changed

+152829
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/node_modules
33
/package-lock.json
44
/test/node_modules
5+
/test/encoding-indexes.js
56

67
# skip the utilities used to build this library
78
/compiler-latest

EncoderDecoderTogether.src.js

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ var ENCODEINTO_BUILD = false;
33

44
(function(window){
55
"use strict";
6-
var log = Math.log;
7-
var LN2 = Math.LN2;
8-
var clz32 = Math.clz32 || function(x) {return 31 - log(x >>> 0) / LN2 | 0};
6+
//var log = Math.log;
7+
//var LN2 = Math.LN2;
8+
//var clz32 = Math.clz32 || function(x) {return 31 - log(x >>> 0) / LN2 | 0};
99
var fromCharCode = String.fromCharCode;
1010
var Object_prototype_toString = ({}).toString;
1111
var NativeSharedArrayBuffer = window["SharedArrayBuffer"];
1212
var sharedArrayBufferString = NativeSharedArrayBuffer ? Object_prototype_toString.call(NativeSharedArrayBuffer) : "";
1313
var NativeUint8Array = window.Uint8Array;
1414
var patchedU8Array = NativeUint8Array || Array;
1515
var arrayBufferString = Object_prototype_toString.call((NativeUint8Array ? ArrayBuffer : patchedU8Array).prototype);
16+
var window_encodeURIComponent = encodeURIComponent;
17+
var window_parseInt = parseInt;
1618
var TextEncoderPrototype = TextEncoder["prototype"];
1719
var GlobalTextEncoder = window["TextEncoder"];
20+
var decoderRegexp = /[\xc0-\xff][\x80-\xbf]+|[\x80-\xff]/g;
21+
var encoderRegexp = /[\x80-\uD7ff\uDC00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]?/g;
1822
var globalTextEncoderPrototype;
1923
var globalTextEncoderInstance;
2024

@@ -57,16 +61,19 @@ var ENCODEINTO_BUILD = false;
5761
}
5862
function TextDecoder(){};
5963
TextDecoder["prototype"]["decode"] = function(inputArrayOrBuffer){
60-
var buffer = (inputArrayOrBuffer && inputArrayOrBuffer.buffer) || inputArrayOrBuffer;
61-
var asObjectString = Object_prototype_toString.call(buffer);
62-
if (asObjectString !== arrayBufferString && asObjectString !== sharedArrayBufferString && inputArrayOrBuffer !== undefined)
63-
throw TypeError("Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
64-
var inputAs8 = NativeUint8Array ? new patchedU8Array(buffer) : buffer;
64+
var inputAs8 = inputArrayOrBuffer;
65+
if (!inputAs8 || inputAs8.constructor !== patchedU8Array) {
66+
var buffer = (inputArrayOrBuffer && inputArrayOrBuffer.buffer) || inputArrayOrBuffer;
67+
var asObjectString = Object_prototype_toString.call(buffer);
68+
if (asObjectString !== arrayBufferString && asObjectString !== sharedArrayBufferString && inputArrayOrBuffer !== undefined)
69+
throw TypeError("Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
70+
inputAs8 = /*NativeUint8Array ?*/ new patchedU8Array(buffer); //: buffer;
71+
}
6572
var resultingString = "";
6673
for (var index=0,len=inputAs8.length|0; index<len; index=index+32768|0)
67-
resultingString += fromCharCode.apply(0, inputAs8[NativeUint8Array ? "subarray" : "slice"](index,index+32768|0));
74+
resultingString += fromCharCode.apply(null, NativeUint8Array ? inputAs8.subarray(index,index+32768|0) : inputAs8.slice(index,index+32768|0));
6875

69-
return resultingString.replace(/[\xc0-\xff][\x80-\xbf]+|[\x80-\xff]/g, decoderReplacer);
76+
return resultingString.replace(decoderRegexp, decoderReplacer);
7077
}
7178
if (!window["TextDecoder"]) window["TextDecoder"] = TextDecoder;
7279
//////////////////////////////////////////////////////////////////////////////////////
@@ -101,14 +108,33 @@ var ENCODEINTO_BUILD = false;
101108
TextEncoderPrototype["encode"] = function(inputString){
102109
// 0xc0 => 0b11000000; 0xff => 0b11111111; 0xc0-0xff => 0b11xxxxxx
103110
// 0x80 => 0b10000000; 0xbf => 0b10111111; 0x80-0xbf => 0b10xxxxxx
104-
var encodedString = inputString === void 0 ? "" : ("" + inputString).replace(/[\x80-\uD7ff\uDC00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]?/g, encoderReplacer);
105-
var len=encodedString.length|0, result = new patchedU8Array(len);
106-
for (var i=0; i<len; i=i+1|0)
111+
var encodedString = inputString === void 0 ? "" : ("" + inputString), len=0, result, i=0, pos=0, code=0;
112+
if (encodedString.length < 16384) {
113+
encodedString = window_encodeURIComponent(encodedString);
114+
result = new patchedU8Array(encodedString.length);
115+
116+
117+
for (len=encoded.length|0; i<len; i=i+1|0) {
118+
code = encodedString.charCodeAt(i);
119+
if (code === 37) { // "%"
120+
result[pos] = parseInt(encodedString.substr(pos+1|0, 2), 16)|0;
121+
i = i+2|0;
122+
} else {
123+
result[pos] = code;
124+
}
125+
pos = pos + 1|0;
126+
}
127+
128+
return NativeUint8Array ? result.subarray(0, pos) : result.slice(0, pos);//result[NativeUint8Array ? "subarray" : "slice"](0, pos);
129+
}
130+
encodedString = encodedString.replace(encoderRegexp, encoderReplacer);
131+
len=encodedString.length|0, result = new patchedU8Array(len);
132+
for (i=0; i<len; i=i+1|0)
107133
result[i] = encodedString.charCodeAt(i);
108134
return result;
109135
};
110136
function polyfill_encodeInto(inputString, u8Arr) {
111-
var encodedString = inputString === void 0 ? "" : ("" + inputString).replace(/[\x80-\uD7ff\uDC00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]?/g, encoderReplacer);
137+
var encodedString = inputString === void 0 ? "" : ("" + inputString).replace(encoderRegexp, encoderReplacer);
112138
var len=encodedString.length|0, i=0, char=0, read=0, u8ArrLen = u8Arr.length|0, inputLength=inputString.length|0;
113139
if (u8ArrLen < len) len=u8ArrLen;
114140
putChars: for (; i<len; i=i+1|0) {

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
[![npm version](http://img.shields.io/npm/v/fastestsmallesttextencoderdecoder.svg?label=version)](https://npmjs.org/package/fastestsmallesttextencoderdecoder "View this project on npm")
44
[![GitHub stars](https://img.shields.io/github/stars/anonyco/FastestSmallestTextEncoderDecoder.svg?style=social)](https://github.com/anonyco/FastestSmallestTextEncoderDecoder/stargazers "View others who have stared this repository")
5-
[![GitHub file size in bytes](https://img.shields.io/github/anonyco/FastestSmallestTextEncoderDecoder/blob/master/EncoderDecoderTogether.min.js.svg?label=without%20gzip)](https://github.com/anonyco/FastestSmallestTextEncoderDecoder/blob/master/EncoderDecoderTogether.min.js "File without gzip")
6-
[![GitHub file size in bytes](https://img.shields.io/github/anonyco/FastestSmallestTextEncoderDecoder/blob/master/test/EncoderDecoderTogether.min.js.gz.svg?label=gzip%20applied)](https://github.com/anonyco/FastestSmallestTextEncoderDecoder/blob/master/test/EncoderDecoderTogether.min.js.gz "Gzipped file")
5+
[![GitHub file size in bytes](https://img.shields.io/github/size/AnonyCo/FastestSmallestTextEncoderDecoder/EncoderDecoderTogether.min.js?label=without%20gzip)](https://github.com/anonyco/FastestSmallestTextEncoderDecoder/blob/master/EncoderDecoderTogether.min.js "File without gzip")
6+
[![GitHub file size in bytes](https://img.shields.io/github/size/AnonyCo/FastestSmallestTextEncoderDecoder/test/EncoderDecoderTogether.min.js.gz?label=gzip%20applied)](https://github.com/anonyco/FastestSmallestTextEncoderDecoder/blob/master/test/EncoderDecoderTogether.min.js.gz "Gzipped file")
77
[![npm bundle size (version)](https://img.shields.io/bundlephobia/min/fastestsmallesttextencoderdecoder/latest.svg?color=maroon&label=NPM%20bundle%20size)](https://npmjs.org/package/fastestsmallesttextencoderdecoder "View this project on npm")<!--[![Issues](http://img.shields.io/github/issues/anonyco/FastestSmallestTextEncoderDecoder.svg)]( https://github.com/anonyco/FastestSmallestTextEncoderDecoder/issues )-->
88
[![CC0 license](https://camo.githubusercontent.com/4df6de8c11e31c357bf955b12ab8c55f55c48823/68747470733a2f2f6c6963656e7365627574746f6e732e6e65742f702f7a65726f2f312e302f38387833312e706e67)](https://creativecommons.org/share-your-work/public-domain/cc0/ "This project's liscence")
99
[![npm downloads](https://img.shields.io/npm/dt/fastestsmallesttextencoderdecoder.svg)](https://npmjs.org/package/fastestsmallesttextencoderdecoder "View this project on npm")
@@ -30,7 +30,7 @@ The `nomodule` attribute prevents the script from being needlessly downloaded an
3030

3131
## EncodeInto
3232

33-
See the [MDN here](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto) for documentation. For the TextEncoder.prototype.encodeInto polyfill, please use `https://dl.dropboxusercontent.com/s/i2e2rho1ohtbhfg/EncoderDecoderTogether.min.js?dl=0` for the full package, `https://dl.dropboxusercontent.com/s/nlcgzbr0ayd5pjs/FastestTextEncoderPolyfill.min.js?dl=0` for only TextEncoder and TextEncoder.prototype.encodeInto, and `npm i fastestsmallesttextencoderdecoder-encodeinto` for NodeJS, es6 modules, RequireJS, AngularJS, or whatever it is that floats your boat.
33+
See the [MDN here](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto) for documentation. For the TextEncoder.prototype.encodeInto polyfill, please use `https://dl.dropboxusercontent.com/s/i2e2rho1ohtbhfg/EncoderDecoderTogether.min.js?dl=0` for the full package, `https://dl.dropboxusercontent.com/s/nlcgzbr0ayd5pjs/FastestTextEncoderPolyfill.min.js?dl=0` for only TextEncoder and TextEncoder.prototype.encodeInto, and `npm i fastestsmallesttextencoderdecoder-encodeinto` for NodeJS, es6 modules, RequireJS, AngularJS, or whatever it is that floats your boat. The [encodeInto](https://raw.githubusercontent.com/anonyco/FastestSmallestTextEncoderDecoder/master/encodeInto/) folder of this repository contains the auto-generated encodeInto build of the main project.
3434

3535
## RequireJS and NodeJS
3636

@@ -62,9 +62,6 @@ npm install fastestsmallesttextencoderdecoder
6262

6363
Then, add `import 'fastestsmallesttextencoderdecoder';` to the polyfills.ts file.
6464

65-
## Encode Into branch
66-
67-
The [encodeInto](https://raw.githubusercontent.com/anonyco/FastestSmallestTextEncoderDecoder/master/encodeInto/) folder of this repository contains an encodeInto build of the main project. The encodeInto branch
6865

6966
## Browser Support
7067

@@ -175,3 +172,4 @@ npm run test
175172
## Continuity
176173

177174
I try my best to be a realist, and what's more realistic than death? I am going to die someday and it may be tomorrow in a car crash. You never know. As I have no coder freinds to look out for my projects, I'm looking for anyone who wants to be a collaborator on this project in the event of the unforseen. Reach out to me at wowzeryest@gmail.com. If issues/pulls start piling up over the course of months, assume the worst. As I am trying my best to do my part to help the community, I encourage every developer to share their projects with other people to ensure continuity.
175+

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"build-gzip": "./zopfli -i20 EncoderDecoderTogether.min.js; mv EncoderDecoderTogether.min.js.gz test 2> /dev/null",
4040
"build-encodeinto": "if [ \"${PWD##*/}\" != 'encodeInto' ]; then mkdir -p encodeInto; cd encodeInto; mkdir -p test individual NodeJS; echo 'Please see [fastestsmallesttextencoderdecoder](fastestsmallesttextencoderdecoder) for usage and details' > README.md; ln -fsT ../LICENSE LICENSE; ln -fsT '../closure-compiler.jar' 'closure-compiler.jar';ln -fsT ../zopfli zopfli; sed -e 's@\"fastestsmallesttextencoderdecoder\"@\"fastestsmallesttextencoderdecoder-encodeinto\"@; s@E[N]CODEINTO_BUILD=false@ENCODEINTO_BUILD=true@g; s@gh/AnonyCo/[F]astestSmallestTextEncoderDecoder@gh/AnonyCo/FastestSmallestTextEncoderDecoder/encodeInto@g; s@[.]/EncoderDecoderTogether@..\\/EncoderDecoderTogether@g; s@[.]/NodeJS/@..\\/NodeJS/@g; s@[.]/individual/FastestTextEncoderPolyfill@..\\/individual/FastestTextEncoderPolyfill@g' > package.json < '../package.json'; cd test; for f in *; do if [ ! -e \"../../test/$f\" ]; then unlink \"$f\" 2> /dev/null; fi; done; for i in $(dir -Ab1L ../../test); do ln -fsT \"../../test/$i\" \"./$i\"; done; cd ..; npm run build; cd ..; printf '#!/bin/sh\nnpm install fastestsmallesttextencoderdecoder-encodeinto\n' > gh-pages/install-FastestSmallestTextEncoderDecoder-encodeInto.sh; printf '@npm install fastestsmallesttextencoderdecoder-encodeinto\r\n' > gh-pages/install-FastestSmallestTextEncoderDecoder-encodeInto.bat; fi; wait",
4141
"prepublishOnly": "if [ -f './encodeInto/package.json' ]; then cd encodeInto; npm publish; cd ..; fi",
42-
"test": "if [ \"${PWD##*/}\" != 'encodeInto' ]; then cd encodeInto/test; node --preserve-symlinks --preserve-symlinks-main -- 'test.js' -test-encode-into; cd ../..; fi; cd test; node --preserve-symlinks --preserve-symlinks-main -- 'test.js'"
42+
"test": "if [ \"${PWD##*/}\" != 'encodeInto' ]; then cd encodeInto/test; node --preserve-symlinks --preserve-symlinks-main -- 'test.js' -test-encode-into; cd ../..; fi; cd test; node --preserve-symlinks --preserve-symlinks-main -- 'test.js'",
43+
"benchmark": "cd test; node --preserve-symlinks --preserve-symlinks-main --expose-gc --max-old-space-size=10240 --max-semi-space-size=8192 --noconcurrent_sweeping --nouse-idle-notification -- 'benchmark.js'"
4344
},
4445
"license": "CC0-1.0",
4546
"author": {

0 commit comments

Comments
 (0)