diff options
author | Alan McGovern <alan.mcgovern@gmail.com> | 2012-04-30 20:34:15 +0400 |
---|---|---|
committer | Alan McGovern <alan.mcgovern@gmail.com> | 2012-04-30 23:05:58 +0400 |
commit | cff3d4ffb59a284cae86caf6be49df032a2fa71f (patch) | |
tree | e9a0ffc562e8e8a23f63467d2e9f1c2f9da7be4f | |
parent | 78472c850e0a6dcd3dc59482593a6246bfcf04f3 (diff) |
[Ide] Speed up adding files to the project
FilePath.ProjectVirtualPath is kinda slow when exected 1000's of
times, so use a Dictionary instead of a HashMap for the virtual
paths to remove the need to call GetFile.
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs index f19182c3f2..ad4d95c904 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs @@ -1392,11 +1392,13 @@ namespace MonoDevelop.Ide //and add the ProjectFiles directly. With large project and many files, this should really help perf. //Also, this is a better check because we handle vpaths and links. //FIXME: it would be really nice if project.Files maintained these hashmaps - var vpathsInProject = new HashSet<FilePath> (project.Files.Select (pf => pf.ProjectVirtualPath)); + var vpathsInProject = new Dictionary<FilePath, ProjectFile> (); var filesInProject = new Dictionary<FilePath,ProjectFile> (); - foreach (var pf in project.Files) + foreach (var pf in project.Files) { filesInProject [pf.FilePath] = pf; - + vpathsInProject [pf.ProjectVirtualPath] = pf; + } + using (monitor) { for (int i = 0; i < files.Length; i++) { @@ -1415,10 +1417,11 @@ namespace MonoDevelop.Ide FilePath targetPath = targetPaths[i].CanonicalPath; Debug.Assert (targetPath.IsChildPathOf (project.BaseDirectory)); - + + ProjectFile vfile; var vpath = targetPath.ToRelative (project.BaseDirectory); - if (vpathsInProject.Contains (vpath)) { - if (project.Files.GetFileWithVirtualPath (vpath).FilePath != file) + if (vpathsInProject.TryGetValue (vpath, out vfile)) { + if (vfile.FilePath != file) MessageService.ShowWarning (GettextCatalog.GetString ( "There is a already a file or link in the project with the name '{0}'", vpath)); continue; @@ -1473,7 +1476,7 @@ namespace MonoDevelop.Ide ProjectFile pf = new ProjectFile (file, fileBuildAction) { Link = vpath }; - vpathsInProject.Add (pf.ProjectVirtualPath); + vpathsInProject [pf.ProjectVirtualPath] = pf; filesInProject [pf.FilePath] = pf; newFileList.Add (pf); continue; @@ -1485,7 +1488,7 @@ namespace MonoDevelop.Ide if (MoveCopyFile (file, targetPath, action == AddAction.Move)) { var pf = new ProjectFile (targetPath, fileBuildAction); - vpathsInProject.Add (pf.ProjectVirtualPath); + vpathsInProject [pf.ProjectVirtualPath] = pf; filesInProject [pf.FilePath] = pf; newFileList.Add (pf); } @@ -1508,7 +1511,7 @@ namespace MonoDevelop.Ide return newFileList; } - void AddFileToFolder (List<ProjectFile> newFileList, HashSet<FilePath> vpathsInProject, Dictionary<FilePath, ProjectFile> filesInProject, FilePath file, string fileBuildAction) + void AddFileToFolder (List<ProjectFile> newFileList, Dictionary<FilePath, ProjectFile> vpathsInProject, Dictionary<FilePath, ProjectFile> filesInProject, FilePath file, string fileBuildAction) { //FIXME: MD project system doesn't cope with duplicate includes - project save/load will remove the file ProjectFile pf; @@ -1519,7 +1522,7 @@ namespace MonoDevelop.Ide return; } pf = new ProjectFile (file, fileBuildAction); - vpathsInProject.Add (pf.ProjectVirtualPath); + vpathsInProject [pf.ProjectVirtualPath] = pf; filesInProject [pf.FilePath] = pf; newFileList.Add (pf); } |