You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 29, 2019. It is now read-only.
Recently,I go through the source code of uibs.
when I come to module 'ui.bootstrap.stackedMap' whose code is down here.
angular.module('ui.bootstrap.stackedMap', [])
/**
A helper, internal data structure that acts as a map but also allows getting / removing
elements in the LIFO order
*/
.factory('$$stackedMap', function() {
return {
createNew: function() {
var stack = [];
return {
add: function(key, value) {
stack.push({
key: key,
value: value
});
},
get: function(key) {
for (var i = 0; i < stack.length; i++) {
if (key === stack[i].key) {
return stack[i];
}
}
},
keys: function() {
var keys = [];
for (var i = 0; i < stack.length; i++) {
keys.push(stack[i].key);
}
return keys;
},
top: function() {
return stack[stack.length - 1];
},
remove: function(key) {
var idx = -1;
for (var i = 0; i < stack.length; i++) {
if (key === stack[i].key) {
idx = i;
break;
}
}
return stack.splice(idx, 1)[0];
},
removeTop: function() {
return stack.splice(stack.length - 1, 1)[0];
},
length: function() {
return stack.length;
}
};
}
};
});
I am wondering why the function 'removeTop' not return stack.pop()
I think 'return stack.pop()' and 'return stack.splice(stack.length - 1, 1)[0];' is equivalent but the former is faster(time ratio is about 1:10)
did I miss something?
The text was updated successfully, but these errors were encountered:
deplay
changed the title
ui.bootstrap.stackedMap performance improments?
ui.bootstrap.stackedMap performance improvements?
May 25, 2016
UIBS:1.3.2
Recently,I go through the source code of uibs.
when I come to module 'ui.bootstrap.stackedMap' whose code is down here.
angular.module('ui.bootstrap.stackedMap', [])
/**
A helper, internal data structure that acts as a map but also allows getting / removing
elements in the LIFO order
*/
.factory('$$stackedMap', function() {
return {
createNew: function() {
var stack = [];
};
});
I am wondering why the function 'removeTop' not return stack.pop()
I think 'return stack.pop()' and 'return stack.splice(stack.length - 1, 1)[0];' is equivalent but the former is faster(time ratio is about 1:10)
did I miss something?
The text was updated successfully, but these errors were encountered: