From fd512f4fc4a47f07d639e5578ef9433a5171c43b Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Fri, 14 Dec 2012 19:05:30 -0800 Subject: [PATCH] More efficient toId implementation --- app.js | 6 ++---- battles.js | 7 +++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index 07638867eb..a3b0b43ce3 100644 --- a/app.js +++ b/app.js @@ -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; diff --git a/battles.js b/battles.js index d561a89f5c..a9a09cce7f 100644 --- a/battles.js +++ b/battles.js @@ -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;