Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorMarius Ungureanu <marius.ungureanu@xamarin.com>2016-09-22 15:23:47 +0300
committerMarius Ungureanu <marius.ungureanu@xamarin.com>2016-09-22 15:35:24 +0300
commit37af113fcf3571814e974467e7be80283553f685 (patch)
treec98f71315b135e1b1d3ea1c2b5729903a3c83fd2 /main
parentc5e0ab0e26472a5f0b31f625c3b8b65947542f01 (diff)
[Core] FilePath no longer creates extra strings on IsChildPathof.
Rewrote the algorithm so it creates fewer strings. The only do the check when we get a match on the first path, so it shouldn't slow down the code a lot. On 10,000,000 iterations, the benchmark results are as given: New with slash: 1331ms Old with slash: 1311ms New without slash: 1397ms Old without slash: 3088ms This fixes memory pressure, slightly makes the slash variant slower, but greatly improved the variant without slash.
Diffstat (limited to 'main')
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core/FilePath.cs14
1 files changed, 9 insertions, 5 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FilePath.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FilePath.cs
index 0f8f88efd2..f5a55cf727 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FilePath.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FilePath.cs
@@ -172,11 +172,15 @@ namespace MonoDevelop.Core
}
public bool IsChildPathOf (FilePath basePath)
- {
- if (basePath.fileName [basePath.fileName.Length - 1] != Path.DirectorySeparatorChar)
- return fileName.StartsWith (basePath.fileName + Path.DirectorySeparatorChar, PathComparison);
- else
- return fileName.StartsWith (basePath.fileName, PathComparison);
+ {
+ bool startsWith = fileName.StartsWith (basePath.fileName, PathComparison);
+ if (startsWith && basePath.fileName [basePath.fileName.Length - 1] != Path.DirectorySeparatorChar) {
+ // If the last character isn't a path separator character, check whether the string we're searching in
+ // has more characters than the string we're looking for then check the character.
+ if (fileName.Length > basePath.fileName.Length)
+ startsWith &= fileName [basePath.fileName.Length] == Path.DirectorySeparatorChar;
+ }
+ return startsWith;
}
public FilePath ChangeExtension (string ext)