[gimp] app: a few improvements to gimp-scratch
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: a few improvements to gimp-scratch
- Date: Sat, 1 Dec 2018 15:04:50 +0000 (UTC)
commit f27b38808f5bc1c375839ed972e3b1e289d33052
Author: Ell <ell_se yahoo com>
Date: Sat Dec 1 10:01:51 2018 -0500
app: a few improvements to gimp-scratch
Simplify code a bit, and add branch-prediction annotations.
app/core/gimp-scratch.h | 32 +++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)
---
diff --git a/app/core/gimp-scratch.h b/app/core/gimp-scratch.h
index 7f7197a03c..f450a1bcc8 100644
--- a/app/core/gimp-scratch.h
+++ b/app/core/gimp-scratch.h
@@ -70,10 +70,10 @@ gimp_scratch_alloc (gsize size)
GimpScratchContext *context;
GimpScratchBlock *block;
- if (! size)
+ if (G_UNLIKELY (! size))
return NULL;
- if (size > GIMP_SCRATCH_MAX_BLOCK_SIZE)
+ if (G_UNLIKELY (size > GIMP_SCRATCH_MAX_BLOCK_SIZE))
{
block = gimp_scratch_block_new (size);
block->size = 0;
@@ -83,31 +83,25 @@ gimp_scratch_alloc (gsize size)
context = g_private_get (&gimp_scratch_context);
- if (! context)
+ if (G_UNLIKELY (! context))
{
context = gimp_scratch_context_new ();
g_private_set (&gimp_scratch_context, context);
}
- if (context->n_available_blocks)
+ if (G_LIKELY (context->n_available_blocks))
{
block = context->blocks[--context->n_available_blocks];
- if (block->size < size)
- {
- gimp_scratch_block_free (block);
+ if (G_LIKELY (size <= block->size))
+ return block->data;
- block = gimp_scratch_block_new (size);
-
- context->blocks[context->n_available_blocks] = block;
- }
- }
- else
- {
- block = gimp_scratch_block_new (size);
+ gimp_scratch_block_free (block);
}
+ block = gimp_scratch_block_new (size);
+
return block->data;
}
@@ -116,7 +110,7 @@ gimp_scratch_alloc0 (gsize size)
{
gpointer ptr;
- if (! size)
+ if (G_UNLIKELY (! size))
return NULL;
ptr = gimp_scratch_alloc (size);
@@ -132,12 +126,12 @@ gimp_scratch_free (gpointer ptr)
GimpScratchContext *context;
GimpScratchBlock *block;
- if (! ptr)
+ if (G_UNLIKELY (! ptr))
return;
block = (GimpScratchBlock *) ((guint8 *) ptr - GIMP_SCRATCH_ALIGNMENT);
- if (! block->size)
+ if (G_UNLIKELY (! block->size))
{
gimp_scratch_block_free (block);
@@ -146,7 +140,7 @@ gimp_scratch_free (gpointer ptr)
context = g_private_get (&gimp_scratch_context);
- if (context->n_available_blocks == context->n_blocks)
+ if (G_UNLIKELY (context->n_available_blocks == context->n_blocks))
{
context->n_blocks = MAX (2 * context->n_blocks, 1);
context->blocks = g_renew (GimpScratchBlock *, context->blocks,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]