OLD | NEW |
---|---|
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 if (oldDigest->m_attrsSHA1 != newDigest->m_attrsSHA1) { | 193 if (oldDigest->m_attrsSHA1 != newDigest->m_attrsSHA1) { |
194 // FIXME: Create a function in Element for removing all properties. Take in account whether did/willModifyAttribute are important. | 194 // FIXME: Create a function in Element for removing all properties. Take in account whether did/willModifyAttribute are important. |
195 while (oldElement->attributesWithoutUpdate().size()) { | 195 while (oldElement->attributesWithoutUpdate().size()) { |
196 const Attribute& attribute = oldElement->attributesWithoutUpdate().a t(0); | 196 const Attribute& attribute = oldElement->attributesWithoutUpdate().a t(0); |
197 if (!m_domEditor->removeAttribute(oldElement, attribute.localName(), exceptionState)) | 197 if (!m_domEditor->removeAttribute(oldElement, attribute.localName(), exceptionState)) |
198 return false; | 198 return false; |
199 } | 199 } |
200 | 200 |
201 // FIXME: Create a function in Element for copying properties. cloneData FromElement() is close but not enough for this case. | 201 // FIXME: Create a function in Element for copying properties. cloneData FromElement() is close but not enough for this case. |
202 AttributeCollection attributes = newElement->attributesWithoutUpdate(); | 202 AttributeCollection attributes = newElement->attributesWithoutUpdate(); |
203 AttributeCollection::iterator end = attributes.end(); | 203 for (auto it : attributes) { |
pfeldman
2014/12/16 16:52:10
Here and below: are you creating copies here?
zhaoze.zhou
2014/12/16 18:56:39
Done.
| |
204 for (AttributeCollection::iterator it = attributes.begin(); it != end; + +it) { | 204 if (!m_domEditor->setAttribute(oldElement, it.name().localName(), it .value(), exceptionState)) |
205 if (!m_domEditor->setAttribute(oldElement, it->name().localName(), i t->value(), exceptionState)) | |
206 return false; | 205 return false; |
207 } | 206 } |
208 } | 207 } |
209 | 208 |
210 bool result = innerPatchChildren(oldElement, oldDigest->m_children, newDiges t->m_children, exceptionState); | 209 bool result = innerPatchChildren(oldElement, oldDigest->m_children, newDiges t->m_children, exceptionState); |
211 m_unusedNodesMap.remove(newDigest->m_sha1); | 210 m_unusedNodesMap.remove(newDigest->m_sha1); |
212 return result; | 211 return result; |
213 } | 212 } |
214 | 213 |
215 pair<DOMPatchSupport::ResultMap, DOMPatchSupport::ResultMap> | 214 pair<DOMPatchSupport::ResultMap, DOMPatchSupport::ResultMap> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 DiffTable oldTable; | 248 DiffTable oldTable; |
250 | 249 |
251 for (size_t i = 0; i < newList.size(); ++i) { | 250 for (size_t i = 0; i < newList.size(); ++i) { |
252 newTable.add(newList[i]->m_sha1, Vector<size_t>()).storedValue->value.ap pend(i); | 251 newTable.add(newList[i]->m_sha1, Vector<size_t>()).storedValue->value.ap pend(i); |
253 } | 252 } |
254 | 253 |
255 for (size_t i = 0; i < oldList.size(); ++i) { | 254 for (size_t i = 0; i < oldList.size(); ++i) { |
256 oldTable.add(oldList[i]->m_sha1, Vector<size_t>()).storedValue->value.ap pend(i); | 255 oldTable.add(oldList[i]->m_sha1, Vector<size_t>()).storedValue->value.ap pend(i); |
257 } | 256 } |
258 | 257 |
259 for (DiffTable::iterator newIt = newTable.begin(); newIt != newTable.end(); ++newIt) { | 258 for (auto newIt : newTable) { |
260 if (newIt->value.size() != 1) | 259 if (newIt.value.size() != 1) |
261 continue; | 260 continue; |
262 | 261 |
263 DiffTable::iterator oldIt = oldTable.find(newIt->key); | 262 DiffTable::iterator oldIt = oldTable.find(newIt.key); |
264 if (oldIt == oldTable.end() || oldIt->value.size() != 1) | 263 if (oldIt == oldTable.end() || oldIt->value.size() != 1) |
265 continue; | 264 continue; |
266 | 265 |
267 newMap[newIt->value[0]] = std::make_pair(newList[newIt->value[0]].get(), oldIt->value[0]); | 266 newMap[newIt.value[0]] = std::make_pair(newList[newIt.value[0]].get(), o ldIt->value[0]); |
268 oldMap[oldIt->value[0]] = std::make_pair(oldList[oldIt->value[0]].get(), newIt->value[0]); | 267 oldMap[oldIt->value[0]] = std::make_pair(oldList[oldIt->value[0]].get(), newIt.value[0]); |
269 } | 268 } |
270 | 269 |
271 for (size_t i = 0; newList.size() > 0 && i < newList.size() - 1; ++i) { | 270 for (size_t i = 0; newList.size() > 0 && i < newList.size() - 1; ++i) { |
272 if (!newMap[i].first || newMap[i + 1].first) | 271 if (!newMap[i].first || newMap[i + 1].first) |
273 continue; | 272 continue; |
274 | 273 |
275 size_t j = newMap[i].second + 1; | 274 size_t j = newMap[i].second + 1; |
276 if (j < oldMap.size() && !oldMap[j].first && newList[i + 1]->m_sha1 == o ldList[j]->m_sha1) { | 275 if (j < oldMap.size() && !oldMap[j].first && newList[i + 1]->m_sha1 == o ldList[j]->m_sha1) { |
277 newMap[i + 1] = std::make_pair(newList[i + 1].get(), j); | 276 newMap[i + 1] = std::make_pair(newList[i + 1].get(), j); |
278 oldMap[j] = std::make_pair(oldList[j].get(), i + 1); | 277 oldMap[j] = std::make_pair(oldList[j].get(), i + 1); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 if (oldHead || oldBody) { | 364 if (oldHead || oldBody) { |
366 for (size_t i = 0; i < newList.size(); ++i) { | 365 for (size_t i = 0; i < newList.size(); ++i) { |
367 if (oldHead && isHTMLHeadElement(*newList[i]->m_node)) | 366 if (oldHead && isHTMLHeadElement(*newList[i]->m_node)) |
368 merges.set(newList[i].get(), oldHead); | 367 merges.set(newList[i].get(), oldHead); |
369 if (oldBody && isHTMLBodyElement(*newList[i]->m_node)) | 368 if (oldBody && isHTMLBodyElement(*newList[i]->m_node)) |
370 merges.set(newList[i].get(), oldBody); | 369 merges.set(newList[i].get(), oldBody); |
371 } | 370 } |
372 } | 371 } |
373 | 372 |
374 // 2. Patch nodes marked for merge. | 373 // 2. Patch nodes marked for merge. |
375 for (HashMap<Digest*, Digest*>::iterator it = merges.begin(); it != merges.e nd(); ++it) { | 374 for (auto it : merges) { |
376 if (!innerPatchNode(it->value, it->key, exceptionState)) | 375 if (!innerPatchNode(it.value, it.key, exceptionState)) |
377 return false; | 376 return false; |
378 } | 377 } |
379 | 378 |
380 // 3. Insert missing nodes. | 379 // 3. Insert missing nodes. |
381 for (size_t i = 0; i < newMap.size(); ++i) { | 380 for (size_t i = 0; i < newMap.size(); ++i) { |
382 if (newMap[i].first || merges.contains(newList[i].get())) | 381 if (newMap[i].first || merges.contains(newList[i].get())) |
383 continue; | 382 continue; |
384 if (!insertBeforeAndMarkAsUsed(parentNode, newList[i].get(), NodeTravers al::childAt(*parentNode, i), exceptionState)) | 383 if (!insertBeforeAndMarkAsUsed(parentNode, newList[i].get(), NodeTravers al::childAt(*parentNode, i), exceptionState)) |
385 return false; | 384 return false; |
386 } | 385 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 while (child) { | 424 while (child) { |
426 OwnPtr<Digest> childInfo = createDigest(child, unusedNodesMap); | 425 OwnPtr<Digest> childInfo = createDigest(child, unusedNodesMap); |
427 addStringToDigestor(digestor.get(), childInfo->m_sha1); | 426 addStringToDigestor(digestor.get(), childInfo->m_sha1); |
428 child = child->nextSibling(); | 427 child = child->nextSibling(); |
429 digest->m_children.append(childInfo.release()); | 428 digest->m_children.append(childInfo.release()); |
430 } | 429 } |
431 | 430 |
432 AttributeCollection attributes = element.attributesWithoutUpdate(); | 431 AttributeCollection attributes = element.attributesWithoutUpdate(); |
433 if (!attributes.isEmpty()) { | 432 if (!attributes.isEmpty()) { |
434 OwnPtr<blink::WebCryptoDigestor> attrsDigestor = createDigestor(Hash AlgorithmSha1); | 433 OwnPtr<blink::WebCryptoDigestor> attrsDigestor = createDigestor(Hash AlgorithmSha1); |
435 AttributeCollection::iterator end = attributes.end(); | 434 for (auto it : attributes) { |
436 for (AttributeCollection::iterator it = attributes.begin(); it != en d; ++it) { | 435 addStringToDigestor(attrsDigestor.get(), it.name().toString()); |
437 addStringToDigestor(attrsDigestor.get(), it->name().toString()); | 436 addStringToDigestor(attrsDigestor.get(), it.value().string()); |
438 addStringToDigestor(attrsDigestor.get(), it->value().string()); | |
439 } | 437 } |
440 finishDigestor(attrsDigestor.get(), digestResult); | 438 finishDigestor(attrsDigestor.get(), digestResult); |
441 digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(dig estResult.data()), 10); | 439 digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(dig estResult.data()), 10); |
442 addStringToDigestor(digestor.get(), digest->m_attrsSHA1); | 440 addStringToDigestor(digestor.get(), digest->m_attrsSHA1); |
443 digestResult.clear(); | 441 digestResult.clear(); |
444 } | 442 } |
445 } | 443 } |
446 finishDigestor(digestor.get(), digestResult); | 444 finishDigestor(digestor.get(), digestResult); |
447 digest->m_sha1 = base64Encode(reinterpret_cast<const char*>(digestResult.dat a()), 10); | 445 digest->m_sha1 = base64Encode(reinterpret_cast<const char*>(digestResult.dat a()), 10); |
448 | 446 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) | 508 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) |
511 { | 509 { |
512 fprintf(stderr, "\n\n"); | 510 fprintf(stderr, "\n\n"); |
513 for (size_t i = 0; i < map.size(); ++i) | 511 for (size_t i = 0; i < map.size(); ++i) |
514 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); | 512 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); |
515 } | 513 } |
516 #endif | 514 #endif |
517 | 515 |
518 } // namespace blink | 516 } // namespace blink |
519 | 517 |
OLD | NEW |