[llvm][StringExtras] Add a fail-able version of `fromHex`
authorRiver Riddle <riddleriver@gmail.com>
Wed, 28 Oct 2020 23:46:25 +0000 (16:46 -0700)
committerRiver Riddle <riddleriver@gmail.com>
Wed, 28 Oct 2020 23:58:06 +0000 (16:58 -0700)
commit1095419b10ff222c3cc362be27d97ff561a2181b
tree4fd0ada3047b7393eb90795089bbbaed6dd24cb1
parent49c84fd5a4bd88cbf61ac6888a66c5da07705c5e
[llvm][StringExtras] Add a fail-able version of `fromHex`

This revision adds a fail-able/checked version of `fromHex` that fails when the input string contains a non-hex character. This removes the need for users to have a separate check for if the string contains all hex digits. This becomes very costly for large hex strings given that checking if a string contains only hex digits is effectively the same as just converting it in the first place.

Context: In MLIR we use hex strings to represent very large constants in the textual format of the IR. These changes lead to a large decrease in compile time when parsing these constants (2 seconds -> 1 second).

Differential Revision: https://reviews.llvm.org/D90265
llvm/include/llvm/ADT/StringExtras.h
llvm/unittests/ADT/StringExtrasTest.cpp