Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
perf(options): use object as map instead of array and indexOf to look…
Browse files Browse the repository at this point in the history
…up hashes
  • Loading branch information
Philipp Burgmer committed Jul 21, 2014
1 parent bd6c441 commit c8309d4
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/w11k-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,21 @@ angular.module('w11k.select').directive('w11kSelect', [
var optionsExpParsed = optionParser.parse(optionsExp);

function collection2options(collection, viewValue) {
var viewValueHashes = viewValue.map(function (selectedValue) {
return hashCode(selectedValue);
});
var viewValueHashes = {};

return collection.map(function (option) {
var optionValue = modelElement2value(option);
var i = viewValue.length;
while (i--) {
var hash = hashCode(viewValue[i]);
viewValueHashes[hash] = true;
}

var options = collection.map(function (element) {
var optionValue = modelElement2value(element);
var optionValueHash = hashCode(optionValue);
var optionLabel = modelElement2label(option);
var optionLabel = modelElement2label(element);

var selected;
if (viewValueHashes.indexOf(optionValueHash) !== -1) {
if (viewValueHashes[optionValueHash]) {
selected = true;
}
else {
Expand All @@ -475,10 +479,12 @@ angular.module('w11k.select').directive('w11kSelect', [
return {
hash: optionValueHash.toString(36),
label: optionLabel,
model: option,
model: element,
selected: selected
};
});

return options;
}

function updateOptions() {
Expand Down

0 comments on commit c8309d4

Please sign in to comment.