reducing textlist item construction time by about 80%

This commit is contained in:
rolux 2011-05-24 19:50:53 +02:00
parent ca905a54bb
commit 4eef6ece64
3 changed files with 17 additions and 6 deletions

View file

@ -23,7 +23,7 @@ Ox.load('Geo', function() {
area = Math.sqrt(city.population * 100), area = Math.sqrt(city.population * 100),
latSize = area / Ox.EARTH_CIRCUMFERENCE * 360, latSize = area / Ox.EARTH_CIRCUMFERENCE * 360,
lngSize = area * Ox.getDegreesPerMeter(city.latitude); lngSize = area * Ox.getDegreesPerMeter(city.latitude);
return city.population > 600000/*400000*/ ? { return city.population > 400000/*400000*/ ? {
area: city.population * 100, area: city.population * 100,
countryCode: countryCode, countryCode: countryCode,
editable: true, editable: true,

View file

@ -649,10 +649,11 @@ Ox.List = function(options, self) {
} }
function loadItems() { function loadItems() {
Ox.print('start loadItems')
that.$content.empty(); that.$content.empty();
self.options.items.forEach(function(item, pos) { self.options.items.forEach(function(item, pos) {
// fixme: duplicated // fixme: duplicated
self.$items[pos] = new Ox.ListItem({ self.$items[pos] = Ox.ListItem({
construct: self.options.construct, construct: self.options.construct,
data: item, data: item,
draggable: self.options.draggable, draggable: self.options.draggable,
@ -663,6 +664,7 @@ Ox.List = function(options, self) {
self.$items[pos].appendTo(that.$content); self.$items[pos].appendTo(that.$content);
}); });
self.selected.length && scrollToPosition(self.selected[0]); self.selected.length && scrollToPosition(self.selected[0]);
Ox.print('stop loadItems')
} }
function getPageLength(page) { function getPageLength(page) {
@ -1232,7 +1234,6 @@ Ox.List = function(options, self) {
} }
function updateSort() { function updateSort() {
Ox.print('start sort')
var key = self.options.sort[0].key, var key = self.options.sort[0].key,
map = self.options.sort[0].map, map = self.options.sort[0].map,
operator = self.options.sort[0].operator, operator = self.options.sort[0].operator,
@ -1244,6 +1245,7 @@ Ox.List = function(options, self) {
self.options.items.forEach(function(item) { self.options.items.forEach(function(item) {
sort[item.id] = map ? map(item[key]) : item[key]; sort[item.id] = map ? map(item[key]) : item[key];
}); });
Ox.print('start sort')
self.options.items.sort(function(a, b) { self.options.items.sort(function(a, b) {
var aValue = sort[a.id], var aValue = sort[a.id],
bValue = sort[b.id], bValue = sort[b.id],
@ -1255,6 +1257,7 @@ Ox.List = function(options, self) {
} }
return ret; return ret;
}); });
Ox.print('end sort')
if (selectedIds.length) { if (selectedIds.length) {
self.selected = []; self.selected = [];
self.options.items.forEach(function(item, i) { self.options.items.forEach(function(item, i) {
@ -1269,7 +1272,6 @@ Ox.List = function(options, self) {
getPositions(); getPositions();
} }
} }
Ox.print('end sort')
} }
self.setOption = function(key, value) { self.setOption = function(key, value) {

View file

@ -526,12 +526,20 @@ Ox.TextList = function(options, self) {
} }
function getItemWidth() { function getItemWidth() {
// fixme: this gets called for every constructItem and is slooow
// the proper way to fix this would be to find out how and when
// that.$element.width() might change... which would probably
// mean binding to every SplitPanel and window resize...
// for now, use a cached value
if (!self.cachedWidth || self.cachedWidthTime < +new Date() - 5000) {
self.cachedWidth = that.$element.width();
self.cachedWidthTime = +new Date();
}
return Math.max( return Math.max(
Ox.sum(self.columnWidths), Ox.sum(self.columnWidths),
that.$element.width() - self.cachedWidth -
(self.options.scrollbarVisible ? Ox.UI.SCROLLBAR_SIZE : 0) (self.options.scrollbarVisible ? Ox.UI.SCROLLBAR_SIZE : 0)
); );
//return Ox.sum(self.columnWidths)
} }
function moveColumn(id, pos) { function moveColumn(id, pos) {
@ -776,6 +784,7 @@ Ox.TextList = function(options, self) {
} }
that.size = function() { that.size = function() {
Ox.print('SIZE FUNCTION CALLED')
setWidth(); setWidth();
that.$body.size(); that.$body.size();
} }