BitstreamReader can encounter many types of error and returns Expected<T> to
signal them. This is rich & typesafe, though adds some overhead.
Unfortunately this technique is used for functions as low-level as "read an
n-bit integer" which are called frequently, and the overhead adds up.
This patch tries to avoid this:
- next to low-level functions that return Expected (e.g. Read), adds a lower-level ReadE which returns the value, and signals errors out of band.
- ReadE sets a "last error" object on the stream which needs to be checked
- it turns out there are cases where we can safely elide/combine some checks, simplifying control flow
- Read is still available with the same signature, but implemented on ReadE.
- ReadRecord is converted to use ReadE and friends
- to avoid inlining a bunch of "makeStringError" formatting into hot functions, we convert the errors used to a custom error type which is cheaper.
A motivating use case: clangd builds a clang PCH ones and then reuses it for
many reparses of the main file. This patch speeds up those reparses by ~7%
(tested with clang/lib/Sema/SemaOverload.cpp and clangd/AST.cpp).