mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 06:18:16 +00:00
Use /2 and 2* instead of >>1 and <<1 which are tricky with signed types
Today's compilers generate shift instructions to perform division and multiplications by powers of 2 [1]. `(x >> 1)` looks straightforward enough, but if x is signed the code will fail when x < 0. The compiler knows better: use `x / 2`. That's why we have code like this: (long)((long_u)Rows >> 1)) instead of the cleaner version that generates the same or better machine code: Rows / 2 [1] http://goo.gl/J4WpG7
This commit is contained in:

committed by
Thiago de Arruda

parent
9a5b3eee5f
commit
db23cb05d1
@@ -7162,7 +7162,7 @@ find_internal_func (
|
||||
* Find the function name in the table. Binary search.
|
||||
*/
|
||||
while (first <= last) {
|
||||
x = first + ((unsigned)(last - first) >> 1);
|
||||
x = first + (last - first) / 2;
|
||||
cmp = STRCMP(name, functions[x].f_name);
|
||||
if (cmp < 0)
|
||||
last = x - 1;
|
||||
|
Reference in New Issue
Block a user