diff options
author | 2018-12-25 19:03:26 +0000 | |
---|---|---|
committer | 2018-12-25 19:03:26 +0000 | |
commit | 64701d6a8ecfc3fcbe8d44282ad868eedf106937 (patch) | |
tree | 78c388d0e90fca2e58de1f021c1650a5889e73fe | |
parent | 5f2c8ad4f6f6e01a1d3816b430e9695c03f30472 (diff) |
avoid a pow call if we can
-rw-r--r-- | lib/js/urweb.js | 47 | ||||
-rwxr-xr-x | tests/driver.sh | 6 |
2 files changed, 36 insertions, 17 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); diff --git a/tests/driver.sh b/tests/driver.sh index 879c093d..d20809d0 100755 --- a/tests/driver.sh +++ b/tests/driver.sh @@ -21,5 +21,9 @@ fi $TESTSRV -q -a 127.0.0.1 & echo $! >> $TESTPID sleep 1 -python3 -m unittest $1.py +if [[ $# -eq 1 ]] ; then + python3 -m unittest $1.py +else + python3 -m unittest $1.Suite.$2 +fi kill `cat $TESTPID` |