Skip to content

Commit

Permalink
Removed cache object.
Browse files Browse the repository at this point in the history
Fixes #2.

After thinking about this, I thought the best approach was to remove the cache object. This keeps the encode and decode functions focused on a single responsibility.
  • Loading branch information
ianoxley committed Jan 11, 2013
1 parent 9c483b4 commit 5216ead
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions lib/encdec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
var BASE_58 = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';

alphabet = alphabet || BASE_58;
var baseCount = alphabet.length,
cache = {};
var baseCount = alphabet.length;

return {
encode : function(num) {
Expand All @@ -19,10 +18,6 @@
return '';
}

if (cache[num]) {
return cache[num];
}

var encode = '';

while (num >= baseCount) {
Expand All @@ -35,7 +30,6 @@
encode = alphabet[num] + encode;
}

cache[num] = encode;
return encode;
},

Expand All @@ -44,10 +38,6 @@
return 0;
}

if (cache[s]) {
return cache[s];
}

var decoded = 0,
multi = 1,
reversed = s.split('').reverse().join('');
Expand All @@ -57,7 +47,6 @@
multi = multi * baseCount;
}

cache[s] = decoded;
return decoded;
}
};
Expand Down

0 comments on commit 5216ead

Please sign in to comment.