OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 return traverseMatchingElementsForwardToOffset(static_cast<const ClassNo
deList*>(this), offset, toElement(currentNode), currentOffset, root); | 384 return traverseMatchingElementsForwardToOffset(static_cast<const ClassNo
deList*>(this), offset, toElement(currentNode), currentOffset, root); |
385 default: | 385 default: |
386 return traverseMatchingElementsForwardToOffset(this, offset, toElement(c
urrentNode), currentOffset, root); | 386 return traverseMatchingElementsForwardToOffset(this, offset, toElement(c
urrentNode), currentOffset, root); |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 bool ALWAYS_INLINE LiveNodeListBase::isLastItemCloserThanLastOrCachedItem(unsign
ed offset) const | 390 bool ALWAYS_INLINE LiveNodeListBase::isLastItemCloserThanLastOrCachedItem(unsign
ed offset) const |
391 { | 391 { |
392 ASSERT(isLengthCacheValid()); | 392 ASSERT(isLengthCacheValid()); |
393 unsigned distanceFromLastItem = cachedLength() - offset; | 393 unsigned distanceFromLastItem = cachedLength() - offset; |
394 if (!isItemCacheValid()) | 394 if (!cachedItem()) |
395 return distanceFromLastItem < offset; | 395 return distanceFromLastItem < offset; |
396 | 396 |
397 return cachedItemOffset() < offset && distanceFromLastItem < offset - cached
ItemOffset(); | 397 return cachedItemOffset() < offset && distanceFromLastItem < offset - cached
ItemOffset(); |
398 } | 398 } |
399 | 399 |
400 bool ALWAYS_INLINE LiveNodeListBase::isFirstItemCloserThanCachedItem(unsigned of
fset) const | 400 bool ALWAYS_INLINE LiveNodeListBase::isFirstItemCloserThanCachedItem(unsigned of
fset) const |
401 { | 401 { |
402 ASSERT(isItemCacheValid()); | |
403 if (cachedItemOffset() < offset) | 402 if (cachedItemOffset() < offset) |
404 return false; | 403 return false; |
405 | 404 |
406 unsigned distanceFromCachedItem = cachedItemOffset() - offset; | 405 unsigned distanceFromCachedItem = cachedItemOffset() - offset; |
407 return offset < distanceFromCachedItem; | 406 return offset < distanceFromCachedItem; |
408 } | 407 } |
409 | 408 |
410 unsigned LiveNodeListBase::length() const | 409 unsigned LiveNodeListBase::length() const |
411 { | 410 { |
412 if (isLengthCacheValid()) | 411 if (isLengthCacheValid()) |
413 return cachedLength(); | 412 return cachedLength(); |
414 | 413 |
415 item(UINT_MAX); | 414 item(UINT_MAX); |
416 ASSERT(isLengthCacheValid()); | 415 ASSERT(isLengthCacheValid()); |
417 | 416 |
418 return cachedLength(); | 417 return cachedLength(); |
419 } | 418 } |
420 | 419 |
421 // FIXME: It is silly that these functions are in HTMLCollection.cpp. | 420 // FIXME: It is silly that these functions are in HTMLCollection.cpp. |
422 Node* LiveNodeListBase::item(unsigned offset) const | 421 Node* LiveNodeListBase::item(unsigned offset) const |
423 { | 422 { |
424 if (isItemCacheValid() && cachedItemOffset() == offset) | 423 if (cachedItem() && cachedItemOffset() == offset) |
425 return cachedItem(); | 424 return cachedItem(); |
426 | 425 |
427 if (isLengthCacheValid() && cachedLength() <= offset) | 426 if (isLengthCacheValid() && cachedLength() <= offset) |
428 return 0; | 427 return 0; |
429 | 428 |
430 ContainerNode* root = rootContainerNode(); | 429 ContainerNode* root = rootContainerNode(); |
431 if (!root) { | 430 if (!root) { |
432 // FIMXE: In someTextNode.childNodes case the root is Text. We shouldn't
even make a LiveNodeList for that. | 431 // FIMXE: In someTextNode.childNodes case the root is Text. We shouldn't
even make a LiveNodeList for that. |
433 setLengthCache(0); | 432 setLengthCache(0); |
434 return 0; | 433 return 0; |
435 } | 434 } |
436 | 435 |
437 if (isLengthCacheValid() && !overridesItemAfter() && isLastItemCloserThanLas
tOrCachedItem(offset)) { | 436 if (isLengthCacheValid() && !overridesItemAfter() && isLastItemCloserThanLas
tOrCachedItem(offset)) { |
438 Node* lastItem = itemBefore(0); | 437 Node* lastItem = itemBefore(0); |
439 ASSERT(lastItem); | 438 ASSERT(lastItem); |
440 setItemCache(lastItem, cachedLength() - 1); | 439 setItemCache(lastItem, cachedLength() - 1); |
441 } else if (!isItemCacheValid() || isFirstItemCloserThanCachedItem(offset) ||
(overridesItemAfter() && offset < cachedItemOffset())) { | 440 } else if (!cachedItem() || isFirstItemCloserThanCachedItem(offset) || (over
ridesItemAfter() && offset < cachedItemOffset())) { |
442 Node* firstItem; | 441 Node* firstItem; |
443 if (isLiveNodeListType(type())) | 442 if (isLiveNodeListType(type())) |
444 firstItem = static_cast<const LiveNodeList*>(this)->traverseToFirstE
lement(*root); | 443 firstItem = static_cast<const LiveNodeList*>(this)->traverseToFirstE
lement(*root); |
445 else | 444 else |
446 firstItem = static_cast<const HTMLCollection*>(this)->traverseToFirs
tElement(*root); | 445 firstItem = static_cast<const HTMLCollection*>(this)->traverseToFirs
tElement(*root); |
447 | 446 |
448 if (!firstItem) { | 447 if (!firstItem) { |
449 setLengthCache(0); | 448 setLengthCache(0); |
450 return 0; | 449 return 0; |
451 } | 450 } |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 | 660 |
662 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element*
element) | 661 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element*
element) |
663 { | 662 { |
664 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v
alue; | 663 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v
alue; |
665 if (!vector) | 664 if (!vector) |
666 vector = adoptPtr(new Vector<Element*>); | 665 vector = adoptPtr(new Vector<Element*>); |
667 vector->append(element); | 666 vector->append(element); |
668 } | 667 } |
669 | 668 |
670 } // namespace WebCore | 669 } // namespace WebCore |
OLD | NEW |