[svn:parrot] r47942 - branches/gsoc_nfg/src/string
darbelo at svn.parrot.org
darbelo at svn.parrot.org
Wed Jun 30 23:50:43 UTC 2010
Author: darbelo
Date: Wed Jun 30 23:50:42 2010
New Revision: 47942
URL: https://trac.parrot.org/parrot/changeset/47942
Log:
Improve grapheme table size handling.
Modified:
branches/gsoc_nfg/src/string/grapheme.c
Modified: branches/gsoc_nfg/src/string/grapheme.c
==============================================================================
--- branches/gsoc_nfg/src/string/grapheme.c Wed Jun 30 23:50:31 2010 (r47941)
+++ branches/gsoc_nfg/src/string/grapheme.c Wed Jun 30 23:50:42 2010 (r47942)
@@ -67,12 +67,19 @@
grow_grapheme_table(PARROT_INTERP, grapheme_table *src, UINTVAL n)
{
ASSERT_ARGS(grow_grapheme_table)
- if (src)
- return (grapheme_table *) mem_sys_realloc(src,
- sizeof (grapheme_table) + (src->size + n) * sizeof (grapheme));
- return create_grapheme_table(interp, n);
-}
+ grapheme_table *table;
+ if (src) {
+ const INTVAL newsize = src->size + n;
+ table = (grapheme_table *) mem_sys_realloc(src, sizeof (grapheme_table)
+ + newsize * sizeof (grapheme));
+ table->size = newsize;
+ }
+ else {
+ table = create_grapheme_table(interp, n);
+ }
+ return table;
+}
void
destroy_grapheme_table(PARROT_INTERP, grapheme_table *table)
@@ -84,6 +91,7 @@
}
mem_gc_free(interp, table);
}
+
void
merge_tables_and_fixup_substring(PARROT_INTERP, STRING *dest,
grapheme_table *table, UINTVAL offset, UINTVAL len)
@@ -103,6 +111,8 @@
new_codepoints = mem_gc_allocate_n_typed(interp, table->used, UChar32);
+ dest->extra = grow_grapheme_table(interp, (grapheme_table *)dest->extra, table->used);
+
/* Add the new graphemes to the old table. */
for (i = 0; i < table->used; i++) {
new_codepoints[i] = add_grapheme(interp,
@@ -122,7 +132,7 @@
grapheme_table *
rehash_grapheme_table(PARROT_INTERP, grapheme_table *src)
{
-// ASSERT_ARGS(rehash_grapheme_table)
+ ASSERT_ARGS(rehash_grapheme_table)
if (src != NULL) {
INTVAL i;
UINTVAL hash = 0xffff;
@@ -160,6 +170,7 @@
mem_gc_allocate_n_typed(interp, src->len, UChar32);
memcpy(table->graphemes[i].codepoints, src->codepoints,
src->len * sizeof (UChar32));
+ table->used++;
return (UChar32) (-1 - i);
}
@@ -185,7 +196,7 @@
table->graphemes[table->used].codepoints[i] =
src->encoding->get_codepoint(interp, src, start + i);
};
- i = table->used;
+ i = table->used++;
return (UChar32) (-1 - i);
}
More information about the parrot-commits
mailing list