diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-04-19 13:12:04 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-24 10:32:47 -0300 |
commit | db23cb05d1d40487007b3c93dd54fab290fd02b7 (patch) | |
tree | e43f5a0cc4314e239015de512b636c93a005dc83 /src/memfile.c | |
parent | 9a5b3eee5f73594f5e3f71411f6a7d4fe2b9da55 (diff) | |
download | rneovim-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/memfile.c')
-rw-r--r-- | src/memfile.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/memfile.c b/src/memfile.c index 497c9ddacd..ee228e6cda 100644 --- a/src/memfile.c +++ b/src/memfile.c @@ -192,7 +192,7 @@ memfile_T *mf_open(char_u *fname, int flags) unsigned page_size = mfp->mf_page_size; while (shift > 0 && (page_size & 1) == 0) { - page_size = page_size >> 1; + page_size /= 2; --shift; } mfp->mf_used_count_max = (p_mm << shift) / page_size; |