Do not throw exception when casting to int.
Make String#number?
patch more efficient by not having an alternate path in case cast was not possible.
The inefficiency was identified in Rack::Timeout::RequestTimeoutException on parti... (gitlab-org/gitlab#435272 - closed). Profiling the reported request showed that the Integer
cast in this gem was taking up a significant amount of wall time. Further investigation showed that the failure was happening occurring only for cases when the string was not a proper number.
I benchmarked and tested 2 alternatives (regex and casting without an exception) here: gitlab-org/gitlab#435272 (comment 1735216350)
Note: I went with a MINOR
update rather than a PATCH
as this is not a fix per se and may affect some functionality.
Edited by Igor Frenkel