Skip to content

Commit 18a3b3f

Browse files
committed
Early return if no extension separator found. Include a descriptive comment too
1 parent c34d666 commit 18a3b3f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

sdk/src/Core/Amazon.Util/AWSSDKUtils.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,15 @@ public static string GetExtension(string path)
203203
return null;
204204

205205
#if NET8_0_OR_GREATER
206+
// LastIndexOf and LastIndexOfAny is vectorized on .NET8+ and is
207+
// signifigantly faster for cases where 'path' does not end with a short file
208+
// extension, such as GUIDs
206209
int extensionIndex = path.AsSpan().LastIndexOf('.');
210+
if (extensionIndex == -1)
211+
{
212+
return string.Empty;
213+
}
214+
207215
int directoryIndex = path.AsSpan().LastIndexOfAny('/', '\\', ':');
208216

209217
// extension separator is found and exists before path separator or path separator doesn't exist

0 commit comments

Comments
 (0)