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

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

Issue 180723006: Have ElementData::attributeItem() return a reference (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 9 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
« no previous file with comments | « Source/core/html/HTMLObjectElement.cpp ('k') | Source/core/inspector/InspectorDOMAgent.cpp » ('j') | 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 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 if (oldNode->nodeType() != Node::ELEMENT_NODE) 178 if (oldNode->nodeType() != Node::ELEMENT_NODE)
179 return true; 179 return true;
180 180
181 // Patch attributes 181 // Patch attributes
182 Element* oldElement = toElement(oldNode); 182 Element* oldElement = toElement(oldNode);
183 Element* newElement = toElement(newNode); 183 Element* newElement = toElement(newNode);
184 if (oldDigest->m_attrsSHA1 != newDigest->m_attrsSHA1) { 184 if (oldDigest->m_attrsSHA1 != newDigest->m_attrsSHA1) {
185 // FIXME: Create a function in Element for removing all properties. Take in account whether did/willModifyAttribute are important. 185 // FIXME: Create a function in Element for removing all properties. Take in account whether did/willModifyAttribute are important.
186 if (oldElement->hasAttributesWithoutUpdate()) { 186 if (oldElement->hasAttributesWithoutUpdate()) {
187 while (oldElement->attributeCount()) { 187 while (oldElement->attributeCount()) {
188 const Attribute* attribute = oldElement->attributeItem(0); 188 const Attribute& attribute = oldElement->attributeItem(0);
189 if (!m_domEditor->removeAttribute(oldElement, attribute->localNa me(), exceptionState)) 189 if (!m_domEditor->removeAttribute(oldElement, attribute.localNam e(), exceptionState))
190 return false; 190 return false;
191 } 191 }
192 } 192 }
193 193
194 // FIXME: Create a function in Element for copying properties. cloneData FromElement() is close but not enough for this case. 194 // FIXME: Create a function in Element for copying properties. cloneData FromElement() is close but not enough for this case.
195 if (newElement->hasAttributesWithoutUpdate()) { 195 if (newElement->hasAttributesWithoutUpdate()) {
196 size_t numAttrs = newElement->attributeCount(); 196 size_t numAttrs = newElement->attributeCount();
197 for (size_t i = 0; i < numAttrs; ++i) { 197 for (size_t i = 0; i < numAttrs; ++i) {
198 const Attribute* attribute = newElement->attributeItem(i); 198 const Attribute& attribute = newElement->attributeItem(i);
199 if (!m_domEditor->setAttribute(oldElement, attribute->name().loc alName(), attribute->value(), exceptionState)) 199 if (!m_domEditor->setAttribute(oldElement, attribute.name().loca lName(), attribute.value(), exceptionState))
200 return false; 200 return false;
201 } 201 }
202 } 202 }
203 } 203 }
204 204
205 bool result = innerPatchChildren(oldElement, oldDigest->m_children, newDiges t->m_children, exceptionState); 205 bool result = innerPatchChildren(oldElement, oldDigest->m_children, newDiges t->m_children, exceptionState);
206 m_unusedNodesMap.remove(newDigest->m_sha1); 206 m_unusedNodesMap.remove(newDigest->m_sha1);
207 return result; 207 return result;
208 } 208 }
209 209
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 addStringToSHA1(sha1, childInfo->m_sha1); 421 addStringToSHA1(sha1, childInfo->m_sha1);
422 child = child->nextSibling(); 422 child = child->nextSibling();
423 digest->m_children.append(childInfo.release()); 423 digest->m_children.append(childInfo.release());
424 } 424 }
425 Element* element = toElement(node); 425 Element* element = toElement(node);
426 426
427 if (element->hasAttributesWithoutUpdate()) { 427 if (element->hasAttributesWithoutUpdate()) {
428 size_t numAttrs = element->attributeCount(); 428 size_t numAttrs = element->attributeCount();
429 SHA1 attrsSHA1; 429 SHA1 attrsSHA1;
430 for (size_t i = 0; i < numAttrs; ++i) { 430 for (size_t i = 0; i < numAttrs; ++i) {
431 const Attribute* attribute = element->attributeItem(i); 431 const Attribute& attribute = element->attributeItem(i);
432 addStringToSHA1(attrsSHA1, attribute->name().toString()); 432 addStringToSHA1(attrsSHA1, attribute.name().toString());
433 addStringToSHA1(attrsSHA1, attribute->value()); 433 addStringToSHA1(attrsSHA1, attribute.value());
434 } 434 }
435 Vector<uint8_t, 20> attrsHash; 435 Vector<uint8_t, 20> attrsHash;
436 attrsSHA1.computeHash(attrsHash); 436 attrsSHA1.computeHash(attrsHash);
437 digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(att rsHash.data()), 10); 437 digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(att rsHash.data()), 10);
438 addStringToSHA1(sha1, digest->m_attrsSHA1); 438 addStringToSHA1(sha1, digest->m_attrsSHA1);
439 } 439 }
440 } 440 }
441 441
442 Vector<uint8_t, 20> hash; 442 Vector<uint8_t, 20> hash;
443 sha1.computeHash(hash); 443 sha1.computeHash(hash);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) 506 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name)
507 { 507 {
508 fprintf(stderr, "\n\n"); 508 fprintf(stderr, "\n\n");
509 for (size_t i = 0; i < map.size(); ++i) 509 for (size_t i = 0; i < map.size(); ++i)
510 fprintf(stderr, "%s[%lu]: %s (%p) - [%lu]\n", name.utf8().data(), i, map [i].first ? nodeName(map[i].first->m_node).utf8().data() : "", map[i].first, map [i].second); 510 fprintf(stderr, "%s[%lu]: %s (%p) - [%lu]\n", name.utf8().data(), i, map [i].first ? nodeName(map[i].first->m_node).utf8().data() : "", map[i].first, map [i].second);
511 } 511 }
512 #endif 512 #endif
513 513
514 } // namespace WebCore 514 } // namespace WebCore
515 515
OLDNEW
« no previous file with comments | « Source/core/html/HTMLObjectElement.cpp ('k') | Source/core/inspector/InspectorDOMAgent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698