From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Matheus Tavares <matheus.bernardino@usp.br>,
Eric Sunshine <sunshine@sunshineco.com>,
Elijah Newren <newren@gmail.com>,
Elijah Newren <newren@gmail.com>
Subject: [PATCH v2 3/3] mem-pool: use consistent pool variable name
Date: Fri, 14 Aug 2020 06:00:20 +0000 [thread overview]
Message-ID: <616402c64e1e01f88e962cf88f4ed1307d986a04.1597384820.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.830.v2.git.git.1597384820.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>
About half the function declarations in mem-pool.h used 'struct mem_pool
*pool', while the other half used 'struct mem_pool *mem_pool'. Make the
code a bit more consistent by just using 'pool' in preference to
'mem_pool' everywhere.
No behavioral changes included; this is just a mechanical rename (though
a line or two was rewrapped as well).
Signed-off-by: Elijah Newren <newren@gmail.com>
---
mem-pool.c | 40 +++++++++++++++++++++-------------------
mem-pool.h | 4 ++--
2 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/mem-pool.c b/mem-pool.c
index 305bcd3542..593605fce2 100644
--- a/mem-pool.c
+++ b/mem-pool.c
@@ -12,11 +12,13 @@
* `insert_after`. If `insert_after` is NULL, then insert block at the
* head of the linked list.
*/
-static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_pool, size_t block_alloc, struct mp_block *insert_after)
+static struct mp_block *mem_pool_alloc_block(struct mem_pool *pool,
+ size_t block_alloc,
+ struct mp_block *insert_after)
{
struct mp_block *p;
- mem_pool->pool_alloc += sizeof(struct mp_block) + block_alloc;
+ pool->pool_alloc += sizeof(struct mp_block) + block_alloc;
p = xmalloc(st_add(sizeof(struct mp_block), block_alloc));
p->next_free = (char *)p->space;
@@ -26,8 +28,8 @@ static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_pool, size_t b
p->next_block = insert_after->next_block;
insert_after->next_block = p;
} else {
- p->next_block = mem_pool->mp_block;
- mem_pool->mp_block = p;
+ p->next_block = pool->mp_block;
+ pool->mp_block = p;
}
return p;
@@ -42,11 +44,11 @@ void mem_pool_init(struct mem_pool *pool, size_t initial_size)
mem_pool_alloc_block(pool, initial_size, NULL);
}
-void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)
+void mem_pool_discard(struct mem_pool *pool, int invalidate_memory)
{
struct mp_block *block, *block_to_free;
- block = mem_pool->mp_block;
+ block = pool->mp_block;
while (block)
{
block_to_free = block;
@@ -58,11 +60,11 @@ void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)
free(block_to_free);
}
- mem_pool->mp_block = NULL;
- mem_pool->pool_alloc = 0;
+ pool->mp_block = NULL;
+ pool->pool_alloc = 0;
}
-void *mem_pool_alloc(struct mem_pool *mem_pool, size_t len)
+void *mem_pool_alloc(struct mem_pool *pool, size_t len)
{
struct mp_block *p = NULL;
void *r;
@@ -71,15 +73,15 @@ void *mem_pool_alloc(struct mem_pool *mem_pool, size_t len)
if (len & (sizeof(uintmax_t) - 1))
len += sizeof(uintmax_t) - (len & (sizeof(uintmax_t) - 1));
- if (mem_pool->mp_block &&
- mem_pool->mp_block->end - mem_pool->mp_block->next_free >= len)
- p = mem_pool->mp_block;
+ if (pool->mp_block &&
+ pool->mp_block->end - pool->mp_block->next_free >= len)
+ p = pool->mp_block;
if (!p) {
- if (len >= (mem_pool->block_alloc / 2))
- return mem_pool_alloc_block(mem_pool, len, mem_pool->mp_block);
+ if (len >= (pool->block_alloc / 2))
+ return mem_pool_alloc_block(pool, len, pool->mp_block);
- p = mem_pool_alloc_block(mem_pool, mem_pool->block_alloc, NULL);
+ p = mem_pool_alloc_block(pool, pool->block_alloc, NULL);
}
r = p->next_free;
@@ -87,10 +89,10 @@ void *mem_pool_alloc(struct mem_pool *mem_pool, size_t len)
return r;
}
-void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_t size)
+void *mem_pool_calloc(struct mem_pool *pool, size_t count, size_t size)
{
size_t len = st_mult(count, size);
- void *r = mem_pool_alloc(mem_pool, len);
+ void *r = mem_pool_alloc(pool, len);
memset(r, 0, len);
return r;
}
@@ -118,12 +120,12 @@ char *mem_pool_xstrndup(struct mem_pool *pool, const char *str, size_t len)
return memcpy(ret, str, minlen);
}
-int mem_pool_contains(struct mem_pool *mem_pool, void *mem)
+int mem_pool_contains(struct mem_pool *pool, void *mem)
{
struct mp_block *p;
/* Check if memory is allocated in a block */
- for (p = mem_pool->mp_block; p; p = p->next_block)
+ for (p = pool->mp_block; p; p = p->next_block)
if ((mem >= ((void *)p->space)) &&
(mem < ((void *)p->end)))
return 1;
diff --git a/mem-pool.h b/mem-pool.h
index a55ee4bc38..022b3097e9 100644
--- a/mem-pool.h
+++ b/mem-pool.h
@@ -29,7 +29,7 @@ void mem_pool_init(struct mem_pool *pool, size_t initial_size);
/*
* Discard all the memory the memory pool is responsible for.
*/
-void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory);
+void mem_pool_discard(struct mem_pool *pool, int invalidate_memory);
/*
* Alloc memory from the mem_pool.
@@ -58,6 +58,6 @@ void mem_pool_combine(struct mem_pool *dst, struct mem_pool *src);
* Check if a memory pointed at by 'mem' is part of the range of
* memory managed by the specified mem_pool.
*/
-int mem_pool_contains(struct mem_pool *mem_pool, void *mem);
+int mem_pool_contains(struct mem_pool *pool, void *mem);
#endif
--
gitgitgadget
next prev parent reply other threads:[~2020-08-14 6:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-14 3:02 [PATCH 0/3] Extend and add a little more generalization to the mem_pool API Elijah Newren via GitGitGadget
2020-08-14 3:02 ` [PATCH 1/3] mem-pool: add convenience functions for xstrdup and xstrndup Elijah Newren via GitGitGadget
2020-08-14 4:42 ` Eric Sunshine
2020-08-14 3:02 ` [PATCH 2/3] mem-pool: use more standard initialization and finalization Elijah Newren via GitGitGadget
2020-08-14 4:38 ` Junio C Hamano
2020-08-14 3:02 ` [PATCH 3/3] mem-pool: use consistent pool variable name Elijah Newren via GitGitGadget
2020-08-14 3:51 ` [PATCH 0/3] Extend and add a little more generalization to the mem_pool API Matheus Tavares Bernardino
2020-08-14 6:00 ` [PATCH v2 " Elijah Newren via GitGitGadget
2020-08-14 6:00 ` [PATCH v2 1/3] mem-pool: add convenience functions for xstrdup and xstrndup Elijah Newren via GitGitGadget
2020-08-14 8:21 ` René Scharfe
2020-08-14 6:00 ` [PATCH v2 2/3] mem-pool: use more standard initialization and finalization Elijah Newren via GitGitGadget
2020-08-14 6:00 ` Elijah Newren via GitGitGadget [this message]
2020-08-15 17:37 ` [PATCH v3 0/3] Extend and add a little more generalization to the mem_pool API Elijah Newren via GitGitGadget
2020-08-15 17:37 ` [PATCH v3 1/3] mem-pool: add convenience functions for strdup and strndup Elijah Newren via GitGitGadget
2020-08-15 17:37 ` [PATCH v3 2/3] mem-pool: use more standard initialization and finalization Elijah Newren via GitGitGadget
2020-08-15 17:37 ` [PATCH v3 3/3] mem-pool: use consistent pool variable name Elijah Newren via GitGitGadget
2020-08-18 19:27 ` [PATCH v3 0/3] Extend and add a little more generalization to the mem_pool API Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=616402c64e1e01f88e962cf88f4ed1307d986a04.1597384820.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=matheus.bernardino@usp.br \
--cc=newren@gmail.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).