8000 Use more robust relative path calculation in markup code generation · vincent-coder0119/wpf@900b82d · GitHub
[go: up one dir, main page]

Skip to content

Commit 900b82d

Browse files
committed
Use more robust relative path calculation in markup code generation
1 parent 8a777ad commit 900b82d

File tree

3 f 8000 iles changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,19 +1568,12 @@ private string ParentFolderPrefix
15681568
{
15691569
get
15701570
{
1571-
string parentFolderPrefix = string.Empty;
1572-
if (TargetPath.StartsWith(SourceFileInfo.SourcePath, StringComparison.OrdinalIgnoreCase))
1573-
{
1574-
string relPath = TargetPath.Substring(SourceFileInfo.SourcePath.Length);
1575-
relPath += SourceFileInfo.RelativeSourceFilePath;
1576-
string[] dirs = relPath.Split(new Char[] { ESCAPED_BACKSLASH_CHAR });
1577-
for (int i = 1; i < dirs.Length; i++)
1578-
{
1579-
parentFolderPrefix += PARENTFOLDER;
1580-
}
1581-
}
1571+
#if NETFX && !NETCOREAPP
1572+
return PathInternal.GetRelativePath(TargetPath, SourceFileInfo.SourcePath, StringComparison.OrdinalIgnoreCase);
1573+
#else
15821574

1583-
return parentFolderPrefix;
1575+
return Path.GetRelativePath(TargetPath, SourceFileInfo.SourcePath);
1576+
#endif
15841577
}
15851578
}
15861579

src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/NETFrameworkGetRelativePath.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,30 @@ internal static int GetRootLength(ReadOnlySpan<char> path)
273273
/// <summary>
274274
/// Gets the count of common characters from the left optionally ignoring case
275275
/// </summary>
276-
internal static int EqualStartingCharacterCount(string first, string second, bool ignoreCase)
276+
internal static unsafe int EqualStartingCharacterCount(string first, string second, bool ignoreCase)
277277
{
278278
if (string.IsNullOrEmpty(first) || string.IsNullOrEmpty(second)) return 0;
279279

280-
// Current index
281-
int index = 0;
280+
int commonChars = 0;
282281

283-
while (index != first.Length && index != second.Length &&
284-
first[index] 8000 == second[index] || (ignoreCase && char.ToUpperInvariant(first[index]) == char.ToUpperInvariant(second[index])))
282+
fixed (char* f = first)
283+
fixed (char* s = second)
285284
{
286-
index++;
285+
char* l = f;
286+
char* r = s;
287+
char* leftEnd = l + first.Length;
288+
char* rightEnd = r + second.Length;
289+
290+
while (l != leftEnd && r != rightEnd
291+
&& (*l == *r || (ignoreCase && char.ToUpperInvariant((*l)) == char.ToUpperInvariant((*r)))))
292+
{
293+
commonChars++;
294+
l++;
295+
r++;
296+
}
287297
}
288298

289-
return index;
299+
return commonChars;
290300
}
291301

292302
/// <summary>

src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/PresentationBuildTasks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
2828
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
2929
<Platforms>AnyCPU;x64</Platforms>
30+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3031
</PropertyGroup>
3132

3233
<ItemDefinitionGroup Condition="'$(CopyTransitiveReferences)'=='true'">

0 commit comments

Comments
 (0)
0