Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Optimized isAlphaNumeric for performance #4159

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions lib/network/dotparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* ====
*
* For label handling, this is an incomplete implementation. From docs (quote #3015):
*
* > the escape sequences "\n", "\l" and "\r" divide the label into lines, centered,
*
* > the escape sequences "\n", "\l" and "\r" divide the label into lines, centered,
* > left-justified, and right-justified, respectively.
*
* Source: http://www.graphviz.org/content/attrs#kescString
Expand Down Expand Up @@ -110,14 +110,31 @@ function nextPreview() {
return dot.charAt(index + 1);
}

var regexAlphaNumeric = /[a-zA-Z_0-9.:#]/;
/**
* Test whether given character is alphabetic or numeric
* Test whether given character is alphabetic or numeric ( a-zA-Z_0-9.:# )
* @param {string} c
* @return {Boolean} isAlphaNumeric
*/
function isAlphaNumeric(c) {
return regexAlphaNumeric.test(c);
var charCode = c.charCodeAt(0);

if(charCode < 47){ // #.
return charCode === 35 || charCode === 46;
}
if(charCode < 59) { // 0-9 and :
return charCode > 47;
}
if(charCode < 91) { // A-Z
return charCode > 64;
}
if (charCode < 96) { // _
return charCode === 95;
}
if(charCode < 123) { // a-z
return charCode > 96;
}

return false;
}

/**
Expand Down