More efficient toId implementation

This commit is contained in:
Guangcong Luo 2012-12-14 19:05:30 -08:00
parent cae58c2fde
commit fd512f4fc4
2 changed files with 5 additions and 8 deletions

6
app.js
View File

@ -257,12 +257,10 @@ if (config.protocol === 'io') {
* Otherwise, an empty string will be returned.
*/
toId = function(text) {
if (typeof text === 'number') text = ''+text;
if (text && text.id) text = text.id;
else if (text && text.userid) text = text.userid;
text = string(text);
if (typeof text !== 'string') return ''; //???
return text.toLowerCase().replace(/[^a-z0-9]+/g, '');
return string(text).toLowerCase().replace(/[^a-z0-9]+/g, '');
};
toUserid = toId;

View File

@ -30,11 +30,10 @@ if (config.crashguard) {
* Otherwise, an empty string will be returned.
*/
toId = function(text) {
if (typeof text === 'number') text = ''+text;
if (text && text.id) text = text.id;
text = string(text);
if (typeof text !== 'string') return ''; //???
return text.toLowerCase().replace(/[^a-z0-9]+/g, '');
else if (text && text.userid) text = text.userid;
return string(text).toLowerCase().replace(/[^a-z0-9]+/g, '');
};
toUserid = toId;