[Pkg-javascript-commits] [node-entities] 58/63: encode: improved `getInverseReplacer` function

Wolfgang Borgert debacle at moszumanska.debian.org
Mon Sep 22 08:15:49 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository node-entities.

commit 463f8e07de7f186f31512b147a1b2630614eae45
Author: fb55 <me at feedic.com>
Date:   Sun Apr 13 22:30:49 2014 +0200

    encode: improved `getInverseReplacer` function
    
    now uses char classes if possible, which perform way better
---
 lib/encode.js | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/encode.js b/lib/encode.js
index 1b44cbc..b426855 100644
--- a/lib/encode.js
+++ b/lib/encode.js
@@ -16,7 +16,21 @@ function getInverseObj(obj){
 }
 
 function getInverseReplacer(inverse){
-	return new RegExp("\\" + Object.keys(inverse).sort().join("|\\"), "g");
+	var single = [],
+	    multiple = [];
+
+	Object.keys(inverse).forEach(function(k){
+		if(k.length === 1){
+			single.push("\\" + k);
+		} else {
+			multiple.push(k);
+		}
+	});
+
+	//TODO add ranges
+	multiple.unshift("[" + single.join() + "]");
+
+	return new RegExp(multiple.join("|"), "g");
 }
 
 var re_nonASCII = /[^\0-\x7F]/g,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-entities.git



More information about the Pkg-javascript-commits mailing list