Skip to content

Commit 714c6d1

Browse files
committed
Int converter: Optimize negative value cast
1 parent 3558b1d commit 714c6d1

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

src/Convert.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,8 @@ constexpr bool spanToT(std::string_view str, T& out)
160160
return false;
161161
}
162162

163-
// Handle the edge case where the value exactly matches the signed minimum.
164-
// Casting to a signed type directly would cause overflow, so assign it explicitly.
165-
if (val == LowerLimit) {
166-
out = std::numeric_limits<T>::min();
167-
return true;
168-
}
169-
170163
// Assign negative value and return
171-
out = -static_cast<T>(val);
164+
out = static_cast<T>(~val + 1);
172165
return true;
173166
}
174167

0 commit comments

Comments
 (0)