-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type mismatch in AppendUint #1805
Comments
This is from before I started maintaining this lib, so I don't know why this was done. And of course we can't change this without breaking backwards compatibility. So I'm afraid we are stuck with this behaviour. |
@erikdubbelboer Thanks! We will fix it on our side then. |
@erikdubbelboer we would have another function which can then also process negative values and we would adapt the other one so that it does not cause a breaking change would this change be acceptable // AppendUint appends n to dst and returns the extended dst.
func AppendUint(dst []byte, n int) []byte {
if n < 0 {
// developer sanity-check
panic("BUG: int must be positive")
}
return AppendInt(dst, n)
}
func AppendInt(dst []byte, n int) []byte {
isNegative := n < 0
if isNegative {
n = -n
}
var b [20]byte
buf := b[:]
i := len(buf)
var q int
for n >= 10 {
i--
q = n / 10
buf[i] = '0' + byte(n-q*10)
n = q
}
i--
buf[i] = '0' + byte(n)
dst = append(dst, buf[i:]...)
if isNegative {
// add '-' in front of the number
dst = append(dst[:1], dst...)
dst[0] = '-'
}
return dst
} we will then benchmark and optimize the code, it's just a first draft for now |
That could work. What is the exact reason you need this? Why not add the |
@erikdubbelboer We use the |
But there are other places where you could use this function and we wanted to make it possible to use it within fasthttp as well |
the appendInt of strconv is almost as fast as your function |
That doesn't surprise me. I wouldn't mind a pull that just replaces the fasthttp implementation with AppendInt. |
@erikdubbelboer While keeping the panic for negative values? I can do one. |
Yeah lets keep the panic for now. |
Ok, I will do the PR today. |
@erikdubbelboer PR submitted |
@erikdubbelboer We were implementing some changes in Fiber and noticed that
AppendUint
takes anint
instead of anuint
. We also noticed there's noAppendInt
available.In several parts of Fasthttp when a value below 0 is passed it throws a panic, instead of enforcing this by using
uint
.Is this a bug, or was intended? Seems the code was added a long time ago
Affected code: https://github.com/valyala/fasthttp/blob/master/bytesconv.go#L124
Would it make sense to make the param
uint
and adding another function namedAppendInt
to fasthttp?The text was updated successfully, but these errors were encountered: