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