Changeset 90117 in webkit
- Timestamp:
- Jun 30, 2011 7:11:21 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r90102 r90117 1 2011-06-30 Sheriff Bot <webkit.review.bot@gmail.com> 2 3 Unreviewed, rolling out r90102. 4 http://trac.webkit.org/changeset/90102 5 https://bugs.webkit.org/show_bug.cgi?id=63714 6 7 Lots of tests asserting beneath 8 SVGSMILElement::findInstanceTime (Requested by aroben on 9 #webkit). 10 11 * wtf/StdLibExtras.h: 12 (WTF::binarySearch): 13 1 14 2011-06-30 Oliver Varga <Varga.Oliver@stud.u-szeged.hu> 2 15 -
trunk/Source/JavaScriptCore/wtf/StdLibExtras.h
r90102 r90117 124 124 } 125 125 126 enum BinarySearchMode {127 KeyMustBePresentInArray,128 KeyMustNotBePresentInArray129 };130 131 126 // Binary search algorithm, calls extractKey on pre-sorted elements in array, 132 127 // compares result with key (KeyTypes should be comparable with '--', '<', '>'). 128 // Optimized for cases where the array contains the key, checked by assertions. 133 129 template<typename ArrayType, typename KeyType, KeyType(*extractKey)(ArrayType*)> 134 inline ArrayType* binarySearch(ArrayType* array, size_t size, KeyType key , BinarySearchMode mode = KeyMustBePresentInArray)130 inline ArrayType* binarySearch(ArrayType* array, size_t size, KeyType key) 135 131 { 136 // The array must contain at least one element (pre-condition, array does con tain key).137 // If the array contains onlyone element, no need to do the comparison.132 // The array must contain at least one element (pre-condition, array does conatin key). 133 // If the array only contains one element, no need to do the comparison. 138 134 while (size > 1) { 139 135 // Pick an element to check, half way through the array, and read the value. 140 136 int pos = (size - 1) >> 1; 141 137 KeyType val = extractKey(&array[pos]); 142 138 143 139 // If the key matches, success! 144 140 if (val == key) … … 154 150 } 155 151 156 // In case of BinarySearchMode = KeyMustBePresentInArray 'size' should never reach zero. 157 if (mode == KeyMustBePresentInArray) 158 ASSERT(size); 152 // 'size' should never reach zero. 153 ASSERT(size); 159 154 } 160 161 // In case of BinarySearchMode = KeyMustBePresentInArray if we reach this point 162 // we've chopped down to one element, no need to check it matches 163 if (mode == KeyMustBePresentInArray) { 164 ASSERT(size == 1); 165 ASSERT(key == extractKey(&array[0])); 166 } 167 155 156 // If we reach this point we've chopped down to one element, no need to check it matches 157 ASSERT(size == 1); 158 ASSERT(key == extractKey(&array[0])); 168 159 return &array[0]; 169 160 } -
trunk/Source/WebCore/ChangeLog
r90116 r90117 1 2011-06-30 Sheriff Bot <webkit.review.bot@gmail.com> 2 3 Unreviewed, rolling out r90102. 4 http://trac.webkit.org/changeset/90102 5 https://bugs.webkit.org/show_bug.cgi?id=63714 6 7 Lots of tests asserting beneath 8 SVGSMILElement::findInstanceTime (Requested by aroben on 9 #webkit). 10 11 * svg/animation/SVGSMILElement.cpp: 12 (WebCore::SVGSMILElement::findInstanceTime): 13 1 14 2011-06-30 Andrey Kosyakov <caseq@chromium.org> 2 15 -
trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp
r90102 r90117 617 617 } 618 618 619 inline SMILTime extractTimeFromVector(const SMILTime* position)620 {621 return *position;622 }623 624 619 SMILTime SVGSMILElement::findInstanceTime(BeginOrEnd beginOrEnd, SMILTime minimumTime, bool equalsMinimumOK) const 625 620 { 621 // FIXME: This searches from the beginning which is inefficient. The list is usually not long 622 // (one entry in common cases) but you can construct a case where it does grow. 626 623 const Vector<SMILTime>& list = beginOrEnd == Begin ? m_beginTimes : m_endTimes; 627 int sizeOfList = list.size(); 628 629 if (!sizeOfList) 630 return beginOrEnd == Begin ? SMILTime::unresolved() : SMILTime::indefinite(); 631 632 const SMILTime* result = binarySearch<const SMILTime, SMILTime, extractTimeFromVector>(list.begin(), sizeOfList, minimumTime, WTF::KeyMustNotBePresentInArray); 633 int indexOfResult = result - list.begin(); 634 635 if (sizeOfList - 1 > indexOfResult && list[indexOfResult] < minimumTime) 636 ++indexOfResult; 637 638 ASSERT(indexOfResult < sizeOfList); 639 640 // "The special value "indefinite" does not yield an instance time in the begin list." 641 if (list[indexOfResult].isIndefinite() && beginOrEnd == Begin) 642 return SMILTime::unresolved(); 643 644 if (list[indexOfResult] < minimumTime) 645 return beginOrEnd == Begin ? SMILTime::unresolved() : SMILTime::indefinite(); 646 647 // If the equals is NOT accepted, we have to find a bigger one. 648 if (list[indexOfResult] == minimumTime && !equalsMinimumOK) { 649 if (indexOfResult + 1 >= sizeOfList) 650 return beginOrEnd == Begin ? SMILTime::unresolved() : SMILTime::indefinite(); 651 } 652 653 while (list[indexOfResult] == list[indexOfResult + 1] && indexOfResult < sizeOfList - 1) 654 ++indexOfResult; 655 656 if (list[indexOfResult] > minimumTime) 657 return list[indexOfResult]; 658 if (list[indexOfResult] == minimumTime) { 659 if (indexOfResult + 1 < sizeOfList - 1) 660 return list[indexOfResult + 1]; 661 return beginOrEnd == Begin ? SMILTime::unresolved() : SMILTime::indefinite(); 662 } 663 664 return list[indexOfResult]; 624 for (unsigned n = 0; n < list.size(); ++n) { 625 SMILTime time = list[n]; 626 ASSERT(!time.isUnresolved()); 627 if (time.isIndefinite() && beginOrEnd == Begin) { 628 // "The special value "indefinite" does not yield an instance time in the begin list." 629 continue; 630 } 631 if (equalsMinimumOK) { 632 if (time >= minimumTime) 633 return time; 634 } else if (time > minimumTime) 635 return time; 636 } 637 return beginOrEnd == Begin ? SMILTime::unresolved() : SMILTime::indefinite(); 665 638 } 666 639
Note: See TracChangeset
for help on using the changeset viewer.