Skip to content

Commit 4a134cb

Browse files
committed
Add FindEntry(ReadOnlySpan<char>) overload
1 parent 0c7694d commit 4a134cb

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

ValvePak/ValvePak/Package.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,31 @@ public void SetFileName(string fileName)
171171
/// Optimized packages also support case insensitive search by using a different <see cref="StringComparison"/>.
172172
/// </summary>
173173
/// <param name="filePath">Full path to the file to find.</param>
174-
public PackageEntry? FindEntry(string filePathStr)
174+
/// <remarks>
175+
/// Normalizes the directory path separator from <see cref="WindowsDirectorySeparator"/> (\) to <see cref="DirectorySeparator"/> (/) in <paramref name="filePath"/>.
176+
/// </remarks>
177+
public PackageEntry? FindEntry(string filePath)
175178
{
176-
ArgumentNullException.ThrowIfNull(filePathStr);
179+
ArgumentNullException.ThrowIfNull(filePath);
177180

178181
// Normalize path separators when reading the file list
179-
var filePath = filePathStr.Replace(WindowsDirectorySeparator, DirectorySeparatorChar).AsSpan();
182+
var filePathSpan = filePath.Replace(WindowsDirectorySeparator, DirectorySeparatorChar).AsSpan();
183+
184+
return FindEntry(filePathSpan);
185+
}
180186

187+
/// <summary>
188+
/// Searches for a given file entry in the file list.
189+
///
190+
/// If <see cref="OptimizeEntriesForBinarySearch"/> was called on this package, this method will use <see cref="List{T}.BinarySearch(T, IComparer{T})"/>.
191+
/// Optimized packages also support case insensitive search by using a different <see cref="StringComparison"/>.
192+
/// </summary>
193+
/// <param name="filePath">Full path to the file to find.</param>
194+
/// <remarks>
195+
/// Unlike the <see cref="FindEntry(string)"/> version, this one does not normalize the directory path separator.
196+
/// </remarks>
197+
public PackageEntry? FindEntry(ReadOnlySpan<char> filePath)
198+
{
181199
var lastSeparator = filePath.LastIndexOf(DirectorySeparatorChar);
182200
var directory = lastSeparator > -1 ? filePath[..lastSeparator] : string.Empty;
183201
var fileName = filePath[(lastSeparator + 1)..];
@@ -276,7 +294,7 @@ public void SetFileName(string fileName)
276294

277295
/// <summary>
278296
/// This sorts <see cref="Entries"/> so that it can be searched through using binary search.
279-
/// Use <see cref="StringComparison.OrdinalIgnoreCase"/> if you want <see cref="FindEntry"/> to search case insensitively.
297+
/// Use <see cref="StringComparison.OrdinalIgnoreCase"/> if you want <see cref="FindEntry(string)"/> to search case insensitively.
280298
/// </summary>
281299
/// <remarks>
282300
/// This is experimental and may be removed in a future release.

0 commit comments

Comments
 (0)