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

Side by Side Diff: Source/core/inspector/InspectorDOMAgent.cpp

Issue 298253009: Add iterator object to iterate efficiently over an Element's attributes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Copyright (C) 2009 Joseph Pecoraro 4 * Copyright (C) 2009 Joseph Pecoraro
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 } 686 }
687 687
688 String caseAdjustedName = name ? (shouldIgnoreCase ? name->lower() : *name) : String(); 688 String caseAdjustedName = name ? (shouldIgnoreCase ? name->lower() : *name) : String();
689 689
690 if (!parsedElement->hasAttributes() && name) { 690 if (!parsedElement->hasAttributes() && name) {
691 m_domEditor->removeAttribute(element, caseAdjustedName, errorString); 691 m_domEditor->removeAttribute(element, caseAdjustedName, errorString);
692 return; 692 return;
693 } 693 }
694 694
695 bool foundOriginalAttribute = false; 695 bool foundOriginalAttribute = false;
696 unsigned numAttrs = parsedElement->attributeCount(); 696 AttributeIteratorAccessor attributes = parsedElement->attributesIterator();
697 for (unsigned i = 0; i < numAttrs; ++i) { 697 AttributeConstIterator end = attributes.end();
698 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
698 // Add attribute pair 699 // Add attribute pair
699 const Attribute& attribute = parsedElement->attributeItem(i); 700 String attributeName = it->name().toString();
700 String attributeName = attribute.name().toString();
701 if (shouldIgnoreCase) 701 if (shouldIgnoreCase)
702 attributeName = attributeName.lower(); 702 attributeName = attributeName.lower();
703 foundOriginalAttribute |= name && attributeName == caseAdjustedName; 703 foundOriginalAttribute |= name && attributeName == caseAdjustedName;
704 if (!m_domEditor->setAttribute(element, attributeName, attribute.value() , errorString)) 704 if (!m_domEditor->setAttribute(element, attributeName, it->value(), erro rString))
705 return; 705 return;
706 } 706 }
707 707
708 if (!foundOriginalAttribute && name && !name->stripWhiteSpace().isEmpty()) 708 if (!foundOriginalAttribute && name && !name->stripWhiteSpace().isEmpty())
709 m_domEditor->removeAttribute(element, caseAdjustedName, errorString); 709 m_domEditor->removeAttribute(element, caseAdjustedName, errorString);
710 } 710 }
711 711
712 void InspectorDOMAgent::removeAttribute(ErrorString* errorString, int elementId, const String& name) 712 void InspectorDOMAgent::removeAttribute(ErrorString* errorString, int elementId, const String& name)
713 { 713 {
714 Element* element = assertEditableElement(errorString, elementId); 714 Element* element = assertEditableElement(errorString, elementId);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 || (startTagFound && !endTagFound && node->nodeName().starts With(tagNameQuery, false)) 946 || (startTagFound && !endTagFound && node->nodeName().starts With(tagNameQuery, false))
947 || (!startTagFound && endTagFound && node->nodeName().endsWi th(tagNameQuery, false))) { 947 || (!startTagFound && endTagFound && node->nodeName().endsWi th(tagNameQuery, false))) {
948 resultCollector.add(node); 948 resultCollector.add(node);
949 break; 949 break;
950 } 950 }
951 // Go through all attributes and serialize them. 951 // Go through all attributes and serialize them.
952 const Element* element = toElement(node); 952 const Element* element = toElement(node);
953 if (!element->hasAttributes()) 953 if (!element->hasAttributes())
954 break; 954 break;
955 955
956 unsigned numAttrs = element->attributeCount(); 956 AttributeIteratorAccessor attributes = element->attributesIterat or();
957 for (unsigned i = 0; i < numAttrs; ++i) { 957 AttributeConstIterator end = attributes.end();
958 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
958 // Add attribute pair 959 // Add attribute pair
959 const Attribute& attribute = element->attributeItem(i); 960 if (it->localName().find(whitespaceTrimmedQuery, 0, false) ! = kNotFound) {
960 if (attribute.localName().find(whitespaceTrimmedQuery, 0, fa lse) != kNotFound) {
961 resultCollector.add(node); 961 resultCollector.add(node);
962 break; 962 break;
963 } 963 }
964 size_t foundPosition = attribute.value().find(attributeQuery , 0, false); 964 size_t foundPosition = it->value().find(attributeQuery, 0, f alse);
965 if (foundPosition != kNotFound) { 965 if (foundPosition != kNotFound) {
966 if (!exactAttributeMatch || (!foundPosition && attribute .value().length() == attributeQuery.length())) { 966 if (!exactAttributeMatch || (!foundPosition && it->value ().length() == attributeQuery.length())) {
967 resultCollector.add(node); 967 resultCollector.add(node);
968 break; 968 break;
969 } 969 }
970 } 970 }
971 } 971 }
972 break; 972 break;
973 } 973 }
974 default: 974 default:
975 break; 975 break;
976 } 976 }
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 1561
1562 return value.release(); 1562 return value.release();
1563 } 1563 }
1564 1564
1565 PassRefPtr<TypeBuilder::Array<String> > InspectorDOMAgent::buildArrayForElementA ttributes(Element* element) 1565 PassRefPtr<TypeBuilder::Array<String> > InspectorDOMAgent::buildArrayForElementA ttributes(Element* element)
1566 { 1566 {
1567 RefPtr<TypeBuilder::Array<String> > attributesValue = TypeBuilder::Array<Str ing>::create(); 1567 RefPtr<TypeBuilder::Array<String> > attributesValue = TypeBuilder::Array<Str ing>::create();
1568 // Go through all attributes and serialize them. 1568 // Go through all attributes and serialize them.
1569 if (!element->hasAttributes()) 1569 if (!element->hasAttributes())
1570 return attributesValue.release(); 1570 return attributesValue.release();
1571 unsigned numAttrs = element->attributeCount(); 1571 AttributeIteratorAccessor attributes = element->attributesIterator();
1572 for (unsigned i = 0; i < numAttrs; ++i) { 1572 AttributeConstIterator end = attributes.end();
1573 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
1573 // Add attribute pair 1574 // Add attribute pair
1574 const Attribute& attribute = element->attributeItem(i); 1575 attributesValue->addItem(it->name().toString());
1575 attributesValue->addItem(attribute.name().toString()); 1576 attributesValue->addItem(it->value());
1576 attributesValue->addItem(attribute.value());
1577 } 1577 }
1578 return attributesValue.release(); 1578 return attributesValue.release();
1579 } 1579 }
1580 1580
1581 PassRefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > InspectorDOMAgent::build ArrayForContainerChildren(Node* container, int depth, NodeToIdMap* nodesMap) 1581 PassRefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > InspectorDOMAgent::build ArrayForContainerChildren(Node* container, int depth, NodeToIdMap* nodesMap)
1582 { 1582 {
1583 RefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > children = TypeBuilder:: Array<TypeBuilder::DOM::Node>::create(); 1583 RefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > children = TypeBuilder:: Array<TypeBuilder::DOM::Node>::create();
1584 if (depth == 0) { 1584 if (depth == 0) {
1585 // Special-case the only text child - pretend that container's children have been requested. 1585 // Special-case the only text child - pretend that container's children have been requested.
1586 Node* firstChild = container->firstChild(); 1586 Node* firstChild = container->firstChild();
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 if (!m_documentNodeToIdMap.contains(m_document)) { 2063 if (!m_documentNodeToIdMap.contains(m_document)) {
2064 RefPtr<TypeBuilder::DOM::Node> root; 2064 RefPtr<TypeBuilder::DOM::Node> root;
2065 getDocument(errorString, root); 2065 getDocument(errorString, root);
2066 return errorString->isEmpty(); 2066 return errorString->isEmpty();
2067 } 2067 }
2068 return true; 2068 return true;
2069 } 2069 }
2070 2070
2071 } // namespace WebCore 2071 } // namespace WebCore
2072 2072
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698