panjf2000 / ants

🐜🐜🐜 ants is the most powerful and reliable pooling solution for Go.
https://ants.andypan.me/
MIT License
12.69k stars 1.36k forks source link

bug:aviod int overflow #289

Closed matyle closed 1 year ago

matyle commented 1 year ago

name: Pull request about: Propose changes to the code title: '' labels: '' assignees: ''

1. Are you opening this pull request for bug-fixs, optimizations or new feature?

2. Please describe how these code changes achieve your intention.

3. Please link to the relevant issues (if any).

4. Which documentation changes (if any) need to be made/updated because of this PR?

4. Checklist

panjf2000 commented 1 year ago

Why do we need this code change when we've already resolved the overflow issue?

matyle commented 1 year ago

Why do we need this code change when we've already resolved the overflow issue? The previous method may overflow if l, r are negative numbers. Although the function call is impossible, I think the previous method is too tricky, and frequent calls to cast twice will cause performance loss, thank you

panjf2000 commented 1 year ago

I appreciate your effort but we should not spend too many tricks on this overflow case, considering it's a minimal probability and the current resolution is good enough, visit this for more details.

P.S. The current implementation is taken from sort.