From 6f4b86448759432b01fb25764b59d9dcf88640c9 Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Mon, 17 May 2010 12:01:54 +0200
Subject: [PATCH] QmlJS: Make Snapshot discard outdated Documents.

Previously, fresh versions of a Document would be added to the
_documentsByPath QMultiHash without removing the old version first.
This means Link could pick up old versions of a Document.

Task-number: QTCREATORBUG-1418
---
 src/libs/qmljs/qmljsdocument.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/libs/qmljs/qmljsdocument.cpp b/src/libs/qmljs/qmljsdocument.cpp
index 216fd7a738e..3cb6162d4fc 100644
--- a/src/libs/qmljs/qmljsdocument.cpp
+++ b/src/libs/qmljs/qmljsdocument.cpp
@@ -251,8 +251,14 @@ Snapshot::~Snapshot()
 void Snapshot::insert(const Document::Ptr &document)
 {
     if (document && (document->qmlProgram() || document->jsProgram())) {
-        _documents.insert(document->fileName(), document);
-        _documentsByPath.insert(document->path(), document);
+        const QString fileName = document->fileName();
+        const QString path = document->path();
+
+        Document::Ptr old = _documents.value(fileName);
+        if (old)
+            _documentsByPath.remove(path, old);
+        _documentsByPath.insert(path, document);
+        _documents.insert(fileName, document);
     }
 }
 
-- 
GitLab