Skip to content

Commit 56065f2

Browse files
committed
Factor common code in in_range
SomewhatAccurate [1] inspired me to look at in_range's implemetation. He noticed a pattern. Factor the code based on that pattern. This commit should not change behavior. [1] https://www.twitch.tv/somewhataccurate
1 parent 9bdb827 commit 56065f2

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/quick-lint-js/narrow-cast.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@ constexpr bool in_range([[maybe_unused]] In x) noexcept {
5757
using unsigned_out = make_unsigned_t<Out>;
5858
if constexpr (std::is_same_v<In, Out>) {
5959
return true;
60-
} else if constexpr (std::is_signed_v<In> && std::is_signed_v<Out>) {
60+
} else if constexpr (std::is_signed_v<In> == std::is_signed_v<Out>) {
6161
return out_limits::lowest() <= x && x <= (out_limits::max)();
6262
} else if constexpr (std::is_signed_v<In> && !std::is_signed_v<Out>) {
6363
return 0 <= x && static_cast<unsigned_in>(x) <= (out_limits::max)();
6464
} else if constexpr (!std::is_signed_v<In> && std::is_signed_v<Out>) {
6565
return x <= unsigned_out{(out_limits::max)()};
66-
} else if constexpr (!std::is_signed_v<In> && !std::is_signed_v<Out>) {
67-
return x <= (out_limits::max)();
6866
}
6967
}
7068

0 commit comments

Comments
 (0)