cache reverse lookups from player name to guid - this prevents the potentially slow iteration throughout localStorage for every lookup
This commit is contained in:
parent
f1a6909c8e
commit
9a30c13413
@ -17,14 +17,21 @@ window.getPlayerName = function(guid) {
|
||||
return '{'+guid.slice(0, 12)+'}';
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user