aboutsummaryrefslogtreecommitdiff
path: root/src/window.c
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-04-19 13:12:04 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-24 10:32:47 -0300
commitdb23cb05d1d40487007b3c93dd54fab290fd02b7 (patch)
treee43f5a0cc4314e239015de512b636c93a005dc83 /src/window.c
parent9a5b3eee5f73594f5e3f71411f6a7d4fe2b9da55 (diff)
downloadrneovim-db23cb05d1d40487007b3c93dd54fab290fd02b7.tar.gz
rneovim-db23cb05d1d40487007b3c93dd54fab290fd02b7.tar.bz2
rneovim-db23cb05d1d40487007b3c93dd54fab290fd02b7.zip
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
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/window.c b/src/window.c
index 1b0c2013e9..d47ed22720 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1516,8 +1516,7 @@ win_equal_rec (
if (totwincount == 0)
new_size = room;
else
- new_size = (wincount * room + ((unsigned)totwincount >> 1))
- / totwincount;
+ new_size = (wincount * room + (totwincount / 2)) / totwincount;
if (hnc) { /* add next_curwin size */
next_curwin_size -= p_wiw - (m - n);
new_size += next_curwin_size;
@@ -1638,8 +1637,7 @@ win_equal_rec (
if (totwincount == 0)
new_size = room;
else
- new_size = (wincount * room + ((unsigned)totwincount >> 1))
- / totwincount;
+ new_size = (wincount * room + (totwincount / 2)) / totwincount;
if (hnc) { /* add next_curwin size */
next_curwin_size -= p_wh - (m - n);
new_size += next_curwin_size;
@@ -4644,7 +4642,7 @@ void win_new_width(win_T *wp, int width)
void win_comp_scroll(win_T *wp)
{
- wp->w_p_scr = ((unsigned)wp->w_height >> 1);
+ wp->w_p_scr = wp->w_height / 2;
if (wp->w_p_scr == 0)
wp->w_p_scr = 1;
}