Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Improve Guid parsing performance (#20183)
Browse files Browse the repository at this point in the history
* Improve Guid parsing performance

Significantly improves the performance of parsing all Guid number styles, primarily by avoiding using the StringToInt core helper that was used previously to parse each of the consistuent components, as well as avoiding some unnecessary searches of the strings in order to determine which format is employed.

I kept strong compatibility with the existing implementation, down to what exceptions are thrown when (even when they’re a bit strange).  However, there are a few cases where the error messages in those exceptions differ from what they previously were, due to ambiguities, and IMO it not being worth making the implementation slower to try to maintain the exact same choice.  For example, the string “{0xdddddddd, 0xdddd 0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}}” isn’t parsable, because it’s missing a comma between the second and third components, and with whitespace removed the parser will try to parse “0xdddd0xdddd” and fail to do so.  Previously that would result in an error message “Additional non-parsable characters are at the end of the string”, and now it’ll result in an error message “Guid string should only contain hexadecimal characters.”  Similarly, “(-ddddddd-dddd-dddd-dddd-dddddddddddd)” would previously fail with “Unrecognized Guid format”, and now it’ll also fail with “Guid string should only contain hexadecimal characters.”

* Undo int->uint / short->ushort field changes

* Address PR feedback
  • Loading branch information
stephentoub authored Sep 29, 2018
1 parent ecbbcf6 commit c04fee1
Show file tree
Hide file tree
Showing 3 changed files with 307 additions and 526 deletions.
1 change: 0 additions & 1 deletion src/System.Private.CoreLib/shared/System/Guid.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ public static unsafe Guid NewGuid()
}
}
}

Loading

0 comments on commit c04fee1

Please sign in to comment.