Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: Source/core/css/StylePropertySet.cpp

Issue 1167383004: Optimize MutableStylePropertySet::findPropertyIndex (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix debug build Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
5 * Copyright (C) 2013 Intel Corporation. All rights reserved. 5 * Copyright (C) 2013 Intel Corporation. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // style property set. 493 // style property set.
494 if (m_cssomWrapper) { 494 if (m_cssomWrapper) {
495 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR ule()); 495 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR ule());
496 ASSERT(!m_cssomWrapper->parentElement()); 496 ASSERT(!m_cssomWrapper->parentElement());
497 return m_cssomWrapper.get(); 497 return m_cssomWrapper.get();
498 } 498 }
499 m_cssomWrapper = adoptPtrWillBeNoop(new PropertySetCSSStyleDeclaration(*this )); 499 m_cssomWrapper = adoptPtrWillBeNoop(new PropertySetCSSStyleDeclaration(*this ));
500 return m_cssomWrapper.get(); 500 return m_cssomWrapper.get();
501 } 501 }
502 502
503
504 class CSSPropertyIDComparer {
505 public:
506 explicit CSSPropertyIDComparer(CSSPropertyID propertyID)
507 : m_propertyID(static_cast<uint16_t>(propertyID)) { }
508 bool operator()(const CSSProperty& property) const
509 {
510 if (property.metadata().m_propertyID == m_propertyID) {
511 // Only enabled properties should be part of the style.
512 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID()));
513 return true;
514 }
515 return false;
516 }
517
518 private:
519 CSSPropertyID propertyID() const { return static_cast<CSSPropertyID>(m_prope rtyID); }
520 uint16_t m_propertyID; // Store as uint16_t to avoid casts while comparing.
521 };
522
503 int MutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const 523 int MutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
504 { 524 {
505 // Convert here propertyID into an uint16_t to compare it with the metadata' s m_propertyID to avoid 525 const CSSProperty* begin = m_propertyVector.data();
506 // the compiler converting it to an int multiple times in the loop. 526 const CSSProperty* end = begin + m_propertyVector.size();
507 uint16_t id = static_cast<uint16_t>(propertyID); 527 const CSSProperty* it = std::find_if(begin, end, CSSPropertyIDComparer(prope rtyID));
508 const CSSProperty* properties = m_propertyVector.data();
509 for (int n = m_propertyVector.size() - 1 ; n >= 0; --n) {
510 if (properties[n].metadata().m_propertyID == id) {
511 // Only enabled properties should be part of the style.
512 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID));
513 return n;
514 }
515 }
516 528
517 return -1; 529 return (it == end) ? -1 : it - begin;
518 } 530 }
519 531
520 DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet) 532 DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet)
521 { 533 {
522 #if ENABLE(OILPAN) 534 #if ENABLE(OILPAN)
523 visitor->trace(m_cssomWrapper); 535 visitor->trace(m_cssomWrapper);
524 visitor->trace(m_propertyVector); 536 visitor->trace(m_propertyVector);
525 #endif 537 #endif
526 StylePropertySet::traceAfterDispatch(visitor); 538 StylePropertySet::traceAfterDispatch(visitor);
527 } 539 }
(...skipping 21 matching lines...) Expand all
549 { 561 {
550 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode)); 562 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode));
551 } 563 }
552 564
553 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create( const CSSProperty* properties, unsigned count) 565 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create( const CSSProperty* properties, unsigned count)
554 { 566 {
555 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count)); 567 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count));
556 } 568 }
557 569
558 } // namespace blink 570 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698