diff options
author | fab <fabrice.leal.ch@gmail.com> | 2018-12-25 19:03:26 +0000 |
---|---|---|
committer | fab <fabrice.leal.ch@gmail.com> | 2018-12-25 19:03:26 +0000 |
commit | 64701d6a8ecfc3fcbe8d44282ad868eedf106937 (patch) | |
tree | 78c388d0e90fca2e58de1f021c1650a5889e73fe /lib/js | |
parent | 5f2c8ad4f6f6e01a1d3816b430e9695c03f30472 (diff) |
avoid a pow call if we can
Diffstat (limited to 'lib/js')
-rw-r--r-- | lib/js/urweb.js | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 0182440e..0b482b07 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -229,11 +229,15 @@ var isLowerBitm = [ ]; function isLower(c) { - var cp = ord(c); - var idx = Math.floor(cp / 32); - var byt = isLowerBitm[idx]; + var cp = ord(c); + var idx = Math.floor(cp / 32); + var byt = isLowerBitm[idx]; + if (byt) + { var mask = Math.pow(2, cp - idx * 32); return (byt & mask) != 0; + } + return false; } var isUpperBitm = [ @@ -440,11 +444,14 @@ var isUpperBitm = [ ]; function isUpper(c) { - var cp = ord(c); - var idx = Math.floor(cp / 32); - var byt = isUpperBitm[idx]; + var cp = ord(c); + var idx = Math.floor(cp / 32); + var byt = isUpperBitm[idx]; + if (byt) { var mask = Math.pow(2, cp - idx * 32); return (byt & mask) != 0; + } + return false; } var isAlphaBitm = [ @@ -756,11 +763,14 @@ var isAlphaBitm = [ ]; function isAlpha(c) { - var cp = ord(c); - var idx = Math.floor(cp / 32); - var byt = isAlphaBitm[idx]; + var cp = ord(c); + var idx = Math.floor(cp / 32); + var byt = isAlphaBitm[idx]; + if (byt) { var mask = Math.pow(2, cp - idx * 32); return (byt & mask) != 0; + } + return false; } var isDigitBitm = [ @@ -963,11 +973,14 @@ var isDigitBitm = [ ]; function isDigit(c) { - var cp = ord(c); - var idx = Math.floor(cp / 32); - var byt = isDigitBitm[idx]; + var cp = ord(c); + var idx = Math.floor(cp / 32); + var byt = isDigitBitm[idx]; + if (byt) { var mask = Math.pow(2, cp - idx * 32); return (byt & mask) != 0; + } + return false; } function isAlnum(c) { return isAlpha(c) || isDigit(c); } @@ -1316,14 +1329,16 @@ var isPrintBitm = [ ]; function isPrint(c) { - var cp = ord(c); - var idx = Math.floor(cp / 32); - var byt = isPrintBitm[idx]; + var cp = ord(c); + var idx = Math.floor(cp / 32); + var byt = isPrintBitm[idx]; + if (byt) { var mask = Math.pow(2, cp - idx * 32); return (byt & mask) != 0; + } + return false; } - function toLower(c) { var cp = ord(c); |