Avoid an unnecessary strlen if len is -1. (#169692, Benoit Dejean)

2005-07-19  Matthias Clasen  <mclasen@redhat.com>

        * glib/gstring.c (g_string_chunk_insert_len): Avoid
        an unnecessary strlen if len is -1.  (#169692,
        Benoit Dejean)
This commit is contained in:
Matthias Clasen 2005-07-19 19:05:19 +00:00 committed by Matthias Clasen
parent e2f521eb19
commit 912e4ea3cb
5 changed files with 27 additions and 7 deletions

View File

@ -1,5 +1,9 @@
2005-07-19 Matthias Clasen <mclasen@redhat.com>
* glib/gstring.c (g_string_chunk_insert_len): Avoid
an unnecessary strlen if len is -1. (#169692,
Benoit Dejean)
* glib/gatomic.c (g_atomic_pointer_compare_and_exchange):
Fix g_atomic_pointer_compare_and_exchange on sparc64.
(#167572, Gert Doering)

View File

@ -1,5 +1,9 @@
2005-07-19 Matthias Clasen <mclasen@redhat.com>
* glib/gstring.c (g_string_chunk_insert_len): Avoid
an unnecessary strlen if len is -1. (#169692,
Benoit Dejean)
* glib/gatomic.c (g_atomic_pointer_compare_and_exchange):
Fix g_atomic_pointer_compare_and_exchange on sparc64.
(#167572, Gert Doering)

View File

@ -1,5 +1,9 @@
2005-07-19 Matthias Clasen <mclasen@redhat.com>
* glib/gstring.c (g_string_chunk_insert_len): Avoid
an unnecessary strlen if len is -1. (#169692,
Benoit Dejean)
* glib/gatomic.c (g_atomic_pointer_compare_and_exchange):
Fix g_atomic_pointer_compare_and_exchange on sparc64.
(#167572, Gert Doering)

View File

@ -1,5 +1,9 @@
2005-07-19 Matthias Clasen <mclasen@redhat.com>
* glib/gstring.c (g_string_chunk_insert_len): Avoid
an unnecessary strlen if len is -1. (#169692,
Benoit Dejean)
* glib/gatomic.c (g_atomic_pointer_compare_and_exchange):
Fix g_atomic_pointer_compare_and_exchange on sparc64.
(#167572, Gert Doering)

View File

@ -218,16 +218,19 @@ g_string_chunk_insert_len (GStringChunk *chunk,
const gchar *string,
gssize len)
{
gssize size;
gchar* pos;
g_return_val_if_fail (chunk != NULL, NULL);
if (len < 0)
len = strlen (string);
size = strlen (string);
else
size = len;
if ((chunk->storage_next + len + 1) > chunk->this_size)
if ((chunk->storage_next + size + 1) > chunk->this_size)
{
gsize new_size = nearest_power (chunk->default_size, len + 1);
gsize new_size = nearest_power (chunk->default_size, size + 1);
chunk->storage_list = g_slist_prepend (chunk->storage_list,
g_new (gchar, new_size));
@ -238,12 +241,13 @@ g_string_chunk_insert_len (GStringChunk *chunk,
pos = ((gchar *) chunk->storage_list->data) + chunk->storage_next;
*(pos + len) = '\0';
*(pos + size) = '\0';
strncpy (pos, string, len);
len = strlen (pos);
strncpy (pos, string, size);
if (len > 0)
size = strlen (pos);
chunk->storage_next += len + 1;
chunk->storage_next += size + 1;
return pos;
}