| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "core/inspector/InspectorHistory.h" | 47 #include "core/inspector/InspectorHistory.h" |
| 48 #include "core/xml/parser/XMLDocumentParser.h" | 48 #include "core/xml/parser/XMLDocumentParser.h" |
| 49 #include "platform/Crypto.h" | 49 #include "platform/Crypto.h" |
| 50 #include "public/platform/Platform.h" | 50 #include "public/platform/Platform.h" |
| 51 #include "wtf/Deque.h" | 51 #include "wtf/Deque.h" |
| 52 #include "wtf/HashTraits.h" | 52 #include "wtf/HashTraits.h" |
| 53 #include "wtf/RefPtr.h" | 53 #include "wtf/RefPtr.h" |
| 54 #include "wtf/text/Base64.h" | 54 #include "wtf/text/Base64.h" |
| 55 #include "wtf/text/CString.h" | 55 #include "wtf/text/CString.h" |
| 56 | 56 |
| 57 using namespace std; |
| 58 |
| 57 namespace WebCore { | 59 namespace WebCore { |
| 58 | 60 |
| 59 struct DOMPatchSupport::Digest { | 61 struct DOMPatchSupport::Digest { |
| 60 explicit Digest(Node* node) : m_node(node) { } | 62 explicit Digest(Node* node) : m_node(node) { } |
| 61 | 63 |
| 62 String m_sha1; | 64 String m_sha1; |
| 63 String m_attrsSHA1; | 65 String m_attrsSHA1; |
| 64 Node* m_node; | 66 Node* m_node; |
| 65 Vector<OwnPtr<Digest> > m_children; | 67 Vector<OwnPtr<Digest> > m_children; |
| 66 }; | 68 }; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 258 } |
| 257 | 259 |
| 258 for (DiffTable::iterator newIt = newTable.begin(); newIt != newTable.end();
++newIt) { | 260 for (DiffTable::iterator newIt = newTable.begin(); newIt != newTable.end();
++newIt) { |
| 259 if (newIt->value.size() != 1) | 261 if (newIt->value.size() != 1) |
| 260 continue; | 262 continue; |
| 261 | 263 |
| 262 DiffTable::iterator oldIt = oldTable.find(newIt->key); | 264 DiffTable::iterator oldIt = oldTable.find(newIt->key); |
| 263 if (oldIt == oldTable.end() || oldIt->value.size() != 1) | 265 if (oldIt == oldTable.end() || oldIt->value.size() != 1) |
| 264 continue; | 266 continue; |
| 265 | 267 |
| 266 newMap[newIt->value[0]] = std::make_pair(newList[newIt->value[0]].get(),
oldIt->value[0]); | 268 newMap[newIt->value[0]] = make_pair(newList[newIt->value[0]].get(), oldI
t->value[0]); |
| 267 oldMap[oldIt->value[0]] = std::make_pair(oldList[oldIt->value[0]].get(),
newIt->value[0]); | 269 oldMap[oldIt->value[0]] = make_pair(oldList[oldIt->value[0]].get(), newI
t->value[0]); |
| 268 } | 270 } |
| 269 | 271 |
| 270 for (size_t i = 0; newList.size() > 0 && i < newList.size() - 1; ++i) { | 272 for (size_t i = 0; newList.size() > 0 && i < newList.size() - 1; ++i) { |
| 271 if (!newMap[i].first || newMap[i + 1].first) | 273 if (!newMap[i].first || newMap[i + 1].first) |
| 272 continue; | 274 continue; |
| 273 | 275 |
| 274 size_t j = newMap[i].second + 1; | 276 size_t j = newMap[i].second + 1; |
| 275 if (j < oldMap.size() && !oldMap[j].first && newList[i + 1]->m_sha1 == o
ldList[j]->m_sha1) { | 277 if (j < oldMap.size() && !oldMap[j].first && newList[i + 1]->m_sha1 == o
ldList[j]->m_sha1) { |
| 276 newMap[i + 1] = std::make_pair(newList[i + 1].get(), j); | 278 newMap[i + 1] = make_pair(newList[i + 1].get(), j); |
| 277 oldMap[j] = std::make_pair(oldList[j].get(), i + 1); | 279 oldMap[j] = make_pair(oldList[j].get(), i + 1); |
| 278 } | 280 } |
| 279 } | 281 } |
| 280 | 282 |
| 281 for (size_t i = newList.size() - 1; newList.size() > 0 && i > 0; --i) { | 283 for (size_t i = newList.size() - 1; newList.size() > 0 && i > 0; --i) { |
| 282 if (!newMap[i].first || newMap[i - 1].first || newMap[i].second <= 0) | 284 if (!newMap[i].first || newMap[i - 1].first || newMap[i].second <= 0) |
| 283 continue; | 285 continue; |
| 284 | 286 |
| 285 size_t j = newMap[i].second - 1; | 287 size_t j = newMap[i].second - 1; |
| 286 if (!oldMap[j].first && newList[i - 1]->m_sha1 == oldList[j]->m_sha1) { | 288 if (!oldMap[j].first && newList[i - 1]->m_sha1 == oldList[j]->m_sha1) { |
| 287 newMap[i - 1] = std::make_pair(newList[i - 1].get(), j); | 289 newMap[i - 1] = make_pair(newList[i - 1].get(), j); |
| 288 oldMap[j] = std::make_pair(oldList[j].get(), i - 1); | 290 oldMap[j] = make_pair(oldList[j].get(), i - 1); |
| 289 } | 291 } |
| 290 } | 292 } |
| 291 | 293 |
| 292 #ifdef DEBUG_DOM_PATCH_SUPPORT | 294 #ifdef DEBUG_DOM_PATCH_SUPPORT |
| 293 dumpMap(oldMap, "OLD"); | 295 dumpMap(oldMap, "OLD"); |
| 294 dumpMap(newMap, "NEW"); | 296 dumpMap(newMap, "NEW"); |
| 295 #endif | 297 #endif |
| 296 | 298 |
| 297 return std::make_pair(oldMap, newMap); | 299 return make_pair(oldMap, newMap); |
| 298 } | 300 } |
| 299 | 301 |
| 300 bool DOMPatchSupport::innerPatchChildren(ContainerNode* parentNode, const Vector
<OwnPtr<Digest> >& oldList, const Vector<OwnPtr<Digest> >& newList, ExceptionSta
te& exceptionState) | 302 bool DOMPatchSupport::innerPatchChildren(ContainerNode* parentNode, const Vector
<OwnPtr<Digest> >& oldList, const Vector<OwnPtr<Digest> >& newList, ExceptionSta
te& exceptionState) |
| 301 { | 303 { |
| 302 pair<ResultMap, ResultMap> resultMaps = diff(oldList, newList); | 304 pair<ResultMap, ResultMap> resultMaps = diff(oldList, newList); |
| 303 ResultMap& oldMap = resultMaps.first; | 305 ResultMap& oldMap = resultMaps.first; |
| 304 ResultMap& newMap = resultMaps.second; | 306 ResultMap& newMap = resultMaps.second; |
| 305 | 307 |
| 306 Digest* oldHead = 0; | 308 Digest* oldHead = 0; |
| 307 Digest* oldBody = 0; | 309 Digest* oldBody = 0; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) | 511 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) |
| 510 { | 512 { |
| 511 fprintf(stderr, "\n\n"); | 513 fprintf(stderr, "\n\n"); |
| 512 for (size_t i = 0; i < map.size(); ++i) | 514 for (size_t i = 0; i < map.size(); ++i) |
| 513 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 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); |
| 514 } | 516 } |
| 515 #endif | 517 #endif |
| 516 | 518 |
| 517 } // namespace WebCore | 519 } // namespace WebCore |
| 518 | 520 |
| OLD | NEW |