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

Side by Side Diff: third_party/WebKit/Source/core/dom/SelectorQuery.cpp

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2014 Samsung Electronics. All rights reserved. 3 * Copyright (C) 2014 Samsung Electronics. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 18 matching lines...) Expand all
29 #include "bindings/core/v8/ExceptionState.h" 29 #include "bindings/core/v8/ExceptionState.h"
30 #include "core/css/SelectorChecker.h" 30 #include "core/css/SelectorChecker.h"
31 #include "core/css/parser/CSSParser.h" 31 #include "core/css/parser/CSSParser.h"
32 #include "core/dom/Document.h" 32 #include "core/dom/Document.h"
33 #include "core/dom/ElementTraversal.h" 33 #include "core/dom/ElementTraversal.h"
34 #include "core/dom/ExceptionCode.h" 34 #include "core/dom/ExceptionCode.h"
35 #include "core/dom/Node.h" 35 #include "core/dom/Node.h"
36 #include "core/dom/StaticNodeList.h" 36 #include "core/dom/StaticNodeList.h"
37 #include "core/dom/shadow/ElementShadow.h" 37 #include "core/dom/shadow/ElementShadow.h"
38 #include "core/dom/shadow/ShadowRoot.h" 38 #include "core/dom/shadow/ShadowRoot.h"
39 #include "wtf/PtrUtil.h"
40 #include <memory>
39 41
40 namespace blink { 42 namespace blink {
41 43
42 struct SingleElementSelectorQueryTrait { 44 struct SingleElementSelectorQueryTrait {
43 typedef Element* OutputType; 45 typedef Element* OutputType;
44 static const bool shouldOnlyMatchFirstElement = true; 46 static const bool shouldOnlyMatchFirstElement = true;
45 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element ) 47 ALWAYS_INLINE static void appendElement(OutputType& output, Element& element )
46 { 48 {
47 DCHECK(!output); 49 DCHECK(!output);
48 output = &element; 50 output = &element;
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 DCHECK_EQ(firstSelector.tagQName().namespaceURI(), nullAtom); 520 DCHECK_EQ(firstSelector.tagQName().namespaceURI(), nullAtom);
519 break; 521 break;
520 default: 522 default:
521 break; // If we need another fast path, add here. 523 break; // If we need another fast path, add here.
522 } 524 }
523 } 525 }
524 526
525 findTraverseRootsAndExecute<SelectorQueryTrait>(rootNode, output); 527 findTraverseRootsAndExecute<SelectorQueryTrait>(rootNode, output);
526 } 528 }
527 529
528 PassOwnPtr<SelectorQuery> SelectorQuery::adopt(CSSSelectorList selectorList) 530 std::unique_ptr<SelectorQuery> SelectorQuery::adopt(CSSSelectorList selectorList )
529 { 531 {
530 return adoptPtr(new SelectorQuery(std::move(selectorList))); 532 return wrapUnique(new SelectorQuery(std::move(selectorList)));
531 } 533 }
532 534
533 SelectorQuery::SelectorQuery(CSSSelectorList selectorList) 535 SelectorQuery::SelectorQuery(CSSSelectorList selectorList)
534 { 536 {
535 m_selectorList = std::move(selectorList); 537 m_selectorList = std::move(selectorList);
536 m_selectors.initialize(m_selectorList); 538 m_selectors.initialize(m_selectorList);
537 } 539 }
538 540
539 bool SelectorQuery::matches(Element& element) const 541 bool SelectorQuery::matches(Element& element) const
540 { 542 {
(...skipping 10 matching lines...) Expand all
551 return m_selectors.queryAll(rootNode); 553 return m_selectors.queryAll(rootNode);
552 } 554 }
553 555
554 Element* SelectorQuery::queryFirst(ContainerNode& rootNode) const 556 Element* SelectorQuery::queryFirst(ContainerNode& rootNode) const
555 { 557 {
556 return m_selectors.queryFirst(rootNode); 558 return m_selectors.queryFirst(rootNode);
557 } 559 }
558 560
559 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu ment& document, ExceptionState& exceptionState) 561 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu ment& document, ExceptionState& exceptionState)
560 { 562 {
561 HashMap<AtomicString, OwnPtr<SelectorQuery>>::iterator it = m_entries.find(s electors); 563 HashMap<AtomicString, std::unique_ptr<SelectorQuery>>::iterator it = m_entri es.find(selectors);
562 if (it != m_entries.end()) 564 if (it != m_entries.end())
563 return it->value.get(); 565 return it->value.get();
564 566
565 CSSSelectorList selectorList = CSSParser::parseSelector(CSSParserContext(doc ument, nullptr), nullptr, selectors); 567 CSSSelectorList selectorList = CSSParser::parseSelector(CSSParserContext(doc ument, nullptr), nullptr, selectors);
566 568
567 if (!selectorList.first()) { 569 if (!selectorList.first()) {
568 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no t a valid selector."); 570 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no t a valid selector.");
569 return nullptr; 571 return nullptr;
570 } 572 }
571 573
572 const unsigned maximumSelectorQueryCacheSize = 256; 574 const unsigned maximumSelectorQueryCacheSize = 256;
573 if (m_entries.size() == maximumSelectorQueryCacheSize) 575 if (m_entries.size() == maximumSelectorQueryCacheSize)
574 m_entries.remove(m_entries.begin()); 576 m_entries.remove(m_entries.begin());
575 577
576 return m_entries.add(selectors, SelectorQuery::adopt(std::move(selectorList) )).storedValue->value.get(); 578 return m_entries.add(selectors, SelectorQuery::adopt(std::move(selectorList) )).storedValue->value.get();
577 } 579 }
578 580
579 void SelectorQueryCache::invalidate() 581 void SelectorQueryCache::invalidate()
580 { 582 {
581 m_entries.clear(); 583 m_entries.clear();
582 } 584 }
583 585
584 } // namespace blink 586 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/SelectorQuery.h ('k') | third_party/WebKit/Source/core/dom/SelectorQueryTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698