diff --git a/code/player_names.js b/code/player_names.js index 0d2557d5..5818db79 100644 --- a/code/player_names.js +++ b/code/player_names.js @@ -17,14 +17,21 @@ window.getPlayerName = function(guid) { return '{'+guid.slice(0, 12)+'}'; } -window.playerNameToGuid = function(playerName){ +window._playerNameToGuidCache = {}; + +window.playerNameToGuid = function(playerName) { + var cachedGuid = window._playerNameToGuidCache[playerName]; + if (cachedGuid !== undefined) return cachedGuid; + var guid = null; $.each(Object.keys(localStorage), function(ind,key) { if(playerName === localStorage[key]) { guid = key; - return false; + return false; //break from $.each } }); + + window._playerNameToGuidCache[playerName] = guid; return guid; }