aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliseo Martínez <eliseomarmol@gmail.com>2014-10-24 20:04:14 +0200
committerEliseo Martínez <eliseomarmol@gmail.com>2014-11-06 22:53:43 +0100
commit7d4ec612b164aae0cf65d529ace9a0a2af945d3c (patch)
tree77d199432faea37fec8346082be155bc3b16323b
parent96e7f229a5d7d5461c7518802f298cab47017a77 (diff)
downloadrneovim-7d4ec612b164aae0cf65d529ace9a0a2af945d3c.tar.gz
rneovim-7d4ec612b164aae0cf65d529ace9a0a2af945d3c.tar.bz2
rneovim-7d4ec612b164aae0cf65d529ace9a0a2af945d3c.zip
Review: Remove long_u: memfile: Refactor: int -> bool.
Replace int with bool where appropriate.
-rw-r--r--src/nvim/memfile.c48
-rw-r--r--src/nvim/memfile_defs.h4
-rw-r--r--src/nvim/memline.c50
-rw-r--r--src/nvim/option.c2
4 files changed, 53 insertions, 51 deletions
diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c
index a6fcdcfbeb..f5176abd1c 100644
--- a/src/nvim/memfile.c
+++ b/src/nvim/memfile.c
@@ -48,6 +48,7 @@
#include <inttypes.h>
#include <limits.h>
#include <string.h>
+#include <stdbool.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
@@ -107,7 +108,7 @@ memfile_T *mf_open(char_u *fname, int flags)
mfp->mf_free_first = NULL; // free list is empty
mfp->mf_used_first = NULL; // used list is empty
mfp->mf_used_last = NULL;
- mfp->mf_dirty = FALSE;
+ mfp->mf_dirty = false;
mfp->mf_used_count = 0;
mf_hash_init(&mfp->mf_hash);
mf_hash_init(&mfp->mf_trans);
@@ -180,14 +181,14 @@ int mf_open_file(memfile_T *mfp, char_u *fname)
if (mfp->mf_fd < 0)
return FAIL;
- mfp->mf_dirty = TRUE;
+ mfp->mf_dirty = true;
return OK;
}
/// Close a memory file and optionally delete the associated file.
///
-/// @param del_file TRUE to delete associated file.
-void mf_close(memfile_T *mfp, int del_file)
+/// @param del_file Whether to delete associated file.
+void mf_close(memfile_T *mfp, bool del_file)
{
bhdr_T *hp, *nextp;
@@ -216,8 +217,8 @@ void mf_close(memfile_T *mfp, int del_file)
/// Close the swap file for a memfile. Used when 'swapfile' is reset.
///
-/// @param getlines TRUE to get all lines into memory.
-void mf_close_file (buf_T *buf, int getlines)
+/// @param getlines Whether to get all lines into memory.
+void mf_close_file (buf_T *buf, bool getlines)
{
memfile_T *mfp = buf->b_ml.ml_mfp;
if (mfp == NULL || mfp->mf_fd < 0) // nothing to close
@@ -261,9 +262,9 @@ void mf_new_page_size(memfile_T *mfp, unsigned new_size)
/// Get a new block
///
-/// @param negative TRUE if negative block number desired (data block)
+/// @param negative Whether a negative block number is desired (data block).
/// @param page_count Desired number of pages.
-bhdr_T *mf_new(memfile_T *mfp, int negative, unsigned page_count)
+bhdr_T *mf_new(memfile_T *mfp, bool negative, unsigned page_count)
{
// If we reached the maximum size for the used memory blocks, release one.
// If a bhdr_T is returned, use it and adjust the page_count if necessary.
@@ -313,7 +314,7 @@ bhdr_T *mf_new(memfile_T *mfp, int negative, unsigned page_count)
}
}
hp->bh_flags = BH_LOCKED | BH_DIRTY; // new block is always dirty
- mfp->mf_dirty = TRUE;
+ mfp->mf_dirty = true;
hp->bh_page_count = page_count;
mf_ins_used(mfp, hp);
mf_ins_hash(mfp, hp);
@@ -373,9 +374,9 @@ bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, unsigned page_count)
/// Release the block *hp.
///
-/// @param dirty Block must be written to file later.
-/// @param infile Block should be in file (needed for recovery).
-void mf_put(memfile_T *mfp, bhdr_T *hp, int dirty, int infile)
+/// @param dirty Whether block must be written to file later.
+/// @param infile Whether block should be in file (needed for recovery).
+void mf_put(memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile)
{
unsigned flags = hp->bh_flags;
@@ -384,7 +385,7 @@ void mf_put(memfile_T *mfp, bhdr_T *hp, int dirty, int infile)
flags &= ~BH_LOCKED;
if (dirty) {
flags |= BH_DIRTY;
- mfp->mf_dirty = TRUE;
+ mfp->mf_dirty = true;
}
hp->bh_flags = flags;
if (infile)
@@ -423,7 +424,7 @@ int mf_sync(memfile_T *mfp, int flags)
int got_int_save = got_int;
if (mfp->mf_fd < 0) { // there is no file, nothing to do
- mfp->mf_dirty = FALSE;
+ mfp->mf_dirty = false;
return FAIL;
}
@@ -460,7 +461,7 @@ int mf_sync(memfile_T *mfp, int flags)
// If the whole list is flushed, the memfile is not dirty anymore.
// In case of an error, dirty flag is also set, to avoid trying all the time.
if (hp == NULL || status == FAIL)
- mfp->mf_dirty = FALSE;
+ mfp->mf_dirty = false;
if ((flags & MFS_FLUSH) && *p_sws != NUL) {
#if defined(UNIX)
@@ -500,7 +501,7 @@ void mf_set_dirty(memfile_T *mfp)
for (hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev)
if (hp->bh_bnum > 0)
hp->bh_flags |= BH_DIRTY;
- mfp->mf_dirty = TRUE;
+ mfp->mf_dirty = true;
}
/// Insert block in front of memfile's hash list.
@@ -574,8 +575,8 @@ static bhdr_T *mf_release(memfile_T *mfp, unsigned page_count)
/// Need to release a block if the number of blocks for this memfile is
/// higher than the maximum one or total memory used is over 'maxmemtot'.
- int need_release = (mfp->mf_used_count >= mfp->mf_used_count_max
- || (total_mem_used >> 10) >= (size_t)p_mmt);
+ bool need_release = (mfp->mf_used_count >= mfp->mf_used_count_max
+ || (total_mem_used >> 10) >= (size_t)p_mmt);
/// Try to create swap file if the amount of memory used is getting too high.
if (mfp->mf_fd < 0 && need_release && p_uc) {
@@ -629,11 +630,10 @@ static bhdr_T *mf_release(memfile_T *mfp, unsigned page_count)
///
/// Used in case of out of memory
///
-/// @return TRUE If any memory was released.
-/// FALSE If not.
-int mf_release_all(void)
+/// @return Whether any memory was released.
+bool mf_release_all(void)
{
- int retval = FALSE;
+ bool retval = false;
FOR_ALL_BUFFERS(buf) {
memfile_T *mfp = buf->b_ml.ml_mfp;
if (mfp != NULL) {
@@ -651,7 +651,7 @@ int mf_release_all(void)
mf_rem_hash(mfp, hp);
mf_free_bhdr(hp);
hp = mfp->mf_used_last; // restart, list was changed
- retval = TRUE;
+ retval = true;
} else
hp = hp->bh_prev;
}
@@ -895,7 +895,7 @@ void mf_fullname(memfile_T *mfp)
}
/// Return TRUE if there are any translations pending for memfile.
-int mf_need_trans(memfile_T *mfp)
+bool mf_need_trans(memfile_T *mfp)
{
return mfp->mf_fname != NULL && mfp->mf_neg_count > 0;
}
diff --git a/src/nvim/memfile_defs.h b/src/nvim/memfile_defs.h
index c9c7e9a590..06a7dbe01a 100644
--- a/src/nvim/memfile_defs.h
+++ b/src/nvim/memfile_defs.h
@@ -2,6 +2,8 @@
#define NVIM_MEMFILE_DEFS_H
#include <stdint.h>
+#include <stdbool.h>
+
#include "nvim/types.h"
/// A block number.
@@ -100,7 +102,7 @@ typedef struct memfile {
blocknr_T mf_neg_count; /// number of negative blocks numbers
blocknr_T mf_infile_count; /// number of pages in the file
unsigned mf_page_size; /// number of bytes in a page
- int mf_dirty; /// TRUE if there are dirty blocks
+ bool mf_dirty; /// TRUE if there are dirty blocks
} memfile_T;
#endif // NVIM_MEMFILE_DEFS_H
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index e7673c93e6..97b6dd32c1 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -297,7 +297,7 @@ int ml_open(buf_T *buf)
/*
* fill block0 struct and write page 0
*/
- hp = mf_new(mfp, FALSE, 1);
+ hp = mf_new(mfp, false, 1);
if (hp->bh_bnum != 0) {
EMSG(_("E298: Didn't get block nr 0?"));
goto error;
@@ -331,7 +331,7 @@ int ml_open(buf_T *buf)
* Only works when there's a swapfile, otherwise it's done when the file
* is created.
*/
- mf_put(mfp, hp, TRUE, FALSE);
+ mf_put(mfp, hp, true, false);
if (!buf->b_help && !B_SPELL(buf))
(void)mf_sync(mfp, 0);
@@ -350,7 +350,7 @@ int ml_open(buf_T *buf)
pp->pb_pointer[0].pe_page_count = 1;
pp->pb_pointer[0].pe_old_lnum = 1;
pp->pb_pointer[0].pe_line_count = 1; /* line count after insertion */
- mf_put(mfp, hp, TRUE, FALSE);
+ mf_put(mfp, hp, true, false);
/*
* Allocate first data block and create an empty line 1.
@@ -372,8 +372,8 @@ int ml_open(buf_T *buf)
error:
if (mfp != NULL) {
if (hp)
- mf_put(mfp, hp, FALSE, FALSE);
- mf_close(mfp, TRUE); /* will also free(mfp->mf_fname) */
+ mf_put(mfp, hp, false, false);
+ mf_close(mfp, true); /* will also free(mfp->mf_fname) */
}
buf->b_ml.ml_mfp = NULL;
return FAIL;
@@ -526,7 +526,7 @@ void ml_open_file(buf_T *buf)
break;
}
/* Writing block 0 failed: close the file and try another dir */
- mf_close_file(buf, FALSE);
+ mf_close_file(buf, false);
}
}
@@ -564,7 +564,7 @@ void ml_close(buf_T *buf, int del_file)
{
if (buf->b_ml.ml_mfp == NULL) /* not open */
return;
- mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */
+ mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */
if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY))
free(buf->b_ml.ml_line_ptr);
free(buf->b_ml.ml_stack);
@@ -650,7 +650,7 @@ static void ml_upd_block0(buf_T *buf, upd_block0_T what)
else /* what == UB_SAME_DIR */
set_b0_dir_flag(b0p, buf);
}
- mf_put(mfp, hp, TRUE, FALSE);
+ mf_put(mfp, hp, true, false);
}
/*
@@ -981,7 +981,7 @@ void ml_recover(void)
b0_fenc = vim_strnsave(p, (int)(b0p->b0_fname + fnsize - p));
}
- mf_put(mfp, hp, FALSE, FALSE); /* release block 0 */
+ mf_put(mfp, hp, false, false); /* release block 0 */
hp = NULL;
/*
@@ -1026,7 +1026,7 @@ void ml_recover(void)
serious_error = FALSE;
for (; !got_int; line_breakcheck()) {
if (hp != NULL)
- mf_put(mfp, hp, FALSE, FALSE); /* release previous block */
+ mf_put(mfp, hp, false, false); /* release previous block */
/*
* get block
@@ -1237,8 +1237,8 @@ theend:
recoverymode = FALSE;
if (mfp != NULL) {
if (hp != NULL)
- mf_put(mfp, hp, FALSE, FALSE);
- mf_close(mfp, FALSE); /* will also free(mfp->mf_fname) */
+ mf_put(mfp, hp, false, false);
+ mf_close(mfp, false); /* will also free(mfp->mf_fname) */
}
if (buf != NULL) {
free(buf->b_ml.ml_stack);
@@ -2167,7 +2167,7 @@ ml_append_int (
buf->b_ml.ml_flags |= ML_LOCKED_DIRTY;
if (!newfile && db_idx >= 0 && in_left)
buf->b_ml.ml_flags |= ML_LOCKED_POS;
- mf_put(mfp, hp_new, TRUE, FALSE);
+ mf_put(mfp, hp_new, true, false);
/*
* flush the old data block
@@ -2190,7 +2190,7 @@ ml_append_int (
pp = hp->bh_data; /* must be pointer block */
if (pp->pb_id != PTR_ID) {
EMSG(_("E317: pointer block id wrong 3"));
- mf_put(mfp, hp, FALSE, FALSE);
+ mf_put(mfp, hp, false, false);
return FAIL;
}
/*
@@ -2216,7 +2216,7 @@ ml_append_int (
if (lnum_right != 0)
pp->pb_pointer[pb_idx + 1].pe_old_lnum = lnum_right;
- mf_put(mfp, hp, TRUE, FALSE);
+ mf_put(mfp, hp, true, false);
buf->b_ml.ml_stack_top = stack_idx + 1; /* truncate stack */
if (lineadd) {
@@ -2261,7 +2261,7 @@ ml_append_int (
pp->pb_pointer[0].pe_line_count = buf->b_ml.ml_line_count;
pp->pb_pointer[0].pe_old_lnum = 1;
pp->pb_pointer[0].pe_page_count = 1;
- mf_put(mfp, hp, TRUE, FALSE); /* release block 1 */
+ mf_put(mfp, hp, true, false); /* release block 1 */
hp = hp_new; /* new block is to be split */
pp = pp_new;
CHECK(stack_idx != 0, _("stack_idx should be 0"));
@@ -2313,8 +2313,8 @@ ml_append_int (
bnum_right = hp_new->bh_bnum;
page_count_left = 1;
page_count_right = 1;
- mf_put(mfp, hp, TRUE, FALSE);
- mf_put(mfp, hp_new, TRUE, FALSE);
+ mf_put(mfp, hp, true, false);
+ mf_put(mfp, hp_new, true, false);
}
}
@@ -2464,7 +2464,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, int message)
pp = hp->bh_data; /* must be pointer block */
if (pp->pb_id != PTR_ID) {
EMSG(_("E317: pointer block id wrong 4"));
- mf_put(mfp, hp, FALSE, FALSE);
+ mf_put(mfp, hp, false, false);
return FAIL;
}
count = --(pp->pb_count);
@@ -2474,7 +2474,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, int message)
if (count != idx) /* move entries after the deleted one */
memmove(&pp->pb_pointer[idx], &pp->pb_pointer[idx + 1],
(size_t)(count - idx) * sizeof(PTR_EN));
- mf_put(mfp, hp, TRUE, FALSE);
+ mf_put(mfp, hp, true, false);
buf->b_ml.ml_stack_top = stack_idx; /* truncate stack */
/* fix line count for rest of blocks in the stack */
@@ -2742,7 +2742,7 @@ static bhdr_T *ml_new_data(memfile_T *mfp, int negative, int page_count)
*/
static bhdr_T *ml_new_ptr(memfile_T *mfp)
{
- bhdr_T *hp = mf_new(mfp, FALSE, 1);
+ bhdr_T *hp = mf_new(mfp, false, 1);
PTR_BL *pp = hp->bh_data;
pp->pb_id = PTR_ID;
pp->pb_count = 0;
@@ -2922,11 +2922,11 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
pp->pb_pointer[idx].pe_line_count++;
dirty = TRUE;
}
- mf_put(mfp, hp, dirty, FALSE);
+ mf_put(mfp, hp, dirty, false);
}
error_block:
- mf_put(mfp, hp, FALSE, FALSE);
+ mf_put(mfp, hp, false, false);
error_noblock:
/*
* If action is ML_DELETE or ML_INSERT we have to correct the tree for
@@ -2990,13 +2990,13 @@ static void ml_lineadd(buf_T *buf, int count)
break;
pp = hp->bh_data; /* must be pointer block */
if (pp->pb_id != PTR_ID) {
- mf_put(mfp, hp, FALSE, FALSE);
+ mf_put(mfp, hp, false, false);
EMSG(_("E317: pointer block id wrong 2"));
break;
}
pp->pb_pointer[ip->ip_index].pe_line_count += count;
ip->ip_high += count;
- mf_put(mfp, hp, TRUE, FALSE);
+ mf_put(mfp, hp, true, false);
}
}
diff --git a/src/nvim/option.c b/src/nvim/option.c
index ca868120a0..207be0bd74 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -5010,7 +5010,7 @@ set_bool_option (
else
/* no need to reset curbuf->b_may_swap, ml_open_file() will check
* buf->b_p_swf */
- mf_close_file(curbuf, TRUE); /* remove the swap file */
+ mf_close_file(curbuf, true); /* remove the swap file */
}
/* when 'terse' is set change 'shortmess' */
else if ((int *)varp == &p_terse) {