Skip to content

Commit

Permalink
Early return if no extension separator found. Include a descriptive c…
Browse files Browse the repository at this point in the history
…omment too
  • Loading branch information
stevenaw committed Jun 30, 2024
1 parent 07145c6 commit cbeb741
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sdk/src/Core/Amazon.Util/AWSSDKUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,15 @@ public static string GetExtension(string path)
return null;

#if NET8_0_OR_GREATER
// LastIndexOf and LastIndexOfAny is vectorized on .NET8+ and is
// signifigantly faster for cases where 'path' does not end with a short file
// extension, such as GUIDs
int extensionIndex = path.AsSpan().LastIndexOf('.');
if (extensionIndex == -1)
{
return string.Empty;
}

int directoryIndex = path.AsSpan().LastIndexOfAny('/', '\\', ':');

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

0 comments on commit cbeb741

Please sign in to comment.