You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to be compatible with the old code and keep the code simple and readable, the new code still does not use generics, but uses templates to generate code. So the majority of repetitive code is generated by `overflow_template.sh`.
@@ -26,7 +18,7 @@ go generate
26
18
27
19
#### Arithmetic overflow detection
28
20
```go
29
-
import"github.com/rwxe/overflow"
21
+
import"github.com/JohnCGriffin/overflow"
30
22
31
23
funcmain() {
32
24
addend:= math.MaxInt64 - 5
@@ -115,13 +107,15 @@ There's a good case to be made that a panic is an unidiomatic but proper respons
115
107
116
108
### Performance considerations
117
109
118
-
Compared with the integer type safety libraries of other languages (such as C++), this library uses some seemingly slow operations, such as division. But this does not mean that these methods will be slow, on the contrary, it will be faster than complex implementations in other languages. The reason is that Go does not allow forced inlining, and any complex functions will be abandoned for inlining, resulting in additional calling overhead. Short functions are lightning fast due to automatic inlining. For example, for unsigned 64-bit integer multiplication overflow detection, when inlining is disabled, division takes five times as long as long multiplication, but after automatic inlining is allowed, division takes 1/5 of long multiplication.
110
+
Compared to integer safe libraries in other languages (e.g. C++), this library uses some seemingly slow operations, such as division. But that doesn't mean these methods will be slow. In fact, because of Go's automatic inlining strategy for short functions and compiler optimizations, these operations are actually very fast in benchmark tests, lightning fast.
111
+
112
+
In addition, Go defines the overflow behavior of signed integers, making the detection of signed integer overflow simple and efficient.
119
113
120
114
Note that using `//go:noinline` in your business function will not affect the inlining of the library function. Only disabling global inlining through `-gcflags="-l"` will affect the inlining of this library function.
121
115
122
116
### Basis and dependencies
123
117
124
-
This library is based on Go's official compiler implementation and language specification, which defines the behavior when integer overflow occurs.
118
+
The library is developed based on Go's official compiler implementation (gc) and language specifications.
0 commit comments