SVN commit 1121573 by orlovich: Cleanup some of the ::copy methods to be typesafe for ListImpBase input, and not assuming ListImp... also inline one more thing. M +15 -19 list.cpp M +2 -2 list.h --- trunk/KDE/kdelibs/kjs/list.cpp #1121572:1121573 @@ -211,11 +211,6 @@ } } -void List::clear() -{ - _impBase->size = 0; -} - void List::appendSlowCase(JSValue *v) { ListImp *imp = static_cast(_impBase); @@ -258,20 +253,20 @@ void List::copyFrom(const List& other) { // Assumption: we're empty (e.g. called from copy) - - ListImp* otherImp = static_cast(other._impBase); + ListImpBase* otherImp = other._impBase; ListImp* ourImp = static_cast(_impBase); assert(ourImp->size == 0 && ourImp->capacity == 0); int size = otherImp->size; - int cap = otherImp->capacity; ourImp->size = size; - ourImp->capacity = cap; - if (cap) { - // other used out-of-line buffer -- we should to - ourImp->data = new JSValue*[cap]; + if (size > inlineListValuesSize) { + // need an out-of-line buffer + ourImp->capacity = size; + ourImp->data = new JSValue*[size]; + } else { + ourImp->capacity = 0; } for (int c = 0; c < size; ++c) @@ -284,17 +279,18 @@ List copy; ListImp* ourImp = static_cast(_impBase); - ListImp* otherImp = static_cast(copy._impBase); + ListImpBase* otherImp = copy._impBase; - // We allocate as much space as the other one (even if we could have - // done it inline) int size = otherImp->size; - int cap = otherImp->capacity; ourImp->size = size - 1; - ourImp->capacity = cap; - if (cap) - ourImp->data = new JSValue*[cap]; + if (size > inlineListValuesSize) { + // need an out-of-line buffer + ourImp->capacity = size; + ourImp->data = new JSValue*[size]; + } else { + ourImp->capacity = 0; + } for (int c = 1; c < size; ++c) ourImp->data[c-1] = otherImp->data[c]; --- trunk/KDE/kdelibs/kjs/list.h #1121572:1121573 @@ -65,7 +65,7 @@ /** * Remove all elements from the list. */ - void clear(); + void clear() { _impBase->size = 0; } /* * Resets this List to point to the default empty list @@ -150,7 +150,7 @@ int size = _impBase->size; int newSize = size + 1; if (newSize < inlineListValuesSize) { - // Can just write to the inline byffer + // Can just write to the inline buffer _impBase->data[size] = val; _impBase->size = newSize; } else {