[svn:parrot] r46523 - branches/codestring/src/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue May 11 22:36:12 UTC 2010
Author: bacek
Date: Tue May 11 22:36:11 2010
New Revision: 46523
URL: https://trac.parrot.org/parrot/changeset/46523
Log:
Don't use string allocations in StringBuilder to avoid clash with GC. Use system mem
Modified:
branches/codestring/src/pmc/codestring.pmc
branches/codestring/src/pmc/stringbuilder.pmc
Modified: branches/codestring/src/pmc/codestring.pmc
==============================================================================
--- branches/codestring/src/pmc/codestring.pmc Tue May 11 18:19:28 2010 (r46522)
+++ branches/codestring/src/pmc/codestring.pmc Tue May 11 22:36:11 2010 (r46523)
@@ -49,7 +49,6 @@
VTABLE void init() {
SUPER();
SET_ATTR_linepos(INTERP, SELF, PMCNULL);
- PObj_custom_mark_SET(SELF);
}
/*
Modified: branches/codestring/src/pmc/stringbuilder.pmc
==============================================================================
--- branches/codestring/src/pmc/stringbuilder.pmc Tue May 11 18:19:28 2010 (r46522)
+++ branches/codestring/src/pmc/stringbuilder.pmc Tue May 11 22:36:11 2010 (r46523)
@@ -62,11 +62,17 @@
*/
VTABLE void init_int(INTVAL initial_size) {
- STRING * const buffer = Parrot_str_new_init(INTERP, NULL, initial_size,
- Parrot_default_encoding_ptr, Parrot_default_charset_ptr, 0);
+ STRING * const buffer = mem_gc_allocate_zeroed_typed(INTERP, STRING);
+ buffer->encoding = Parrot_default_encoding_ptr;
+ buffer->charset = Parrot_default_charset_ptr;
+ buffer->flags = PObj_external_FLAG;
+ buffer->_bufstart = buffer->strstart = mem_gc_allocate_n_typed(INTERP,
+ initial_size, char);
+ buffer->_buflen = initial_size;
+
SET_ATTR_buffer(INTERP, SELF, buffer);
- PObj_custom_mark_SET(SELF);
+ PObj_custom_mark_destroy_SETALL(SELF);
}
/*
@@ -80,13 +86,18 @@
*/
VTABLE void mark() {
+ }
+
+ VTABLE void destroy() {
STRING *buffer;
if (!PMC_data(SELF))
return;
GET_ATTR_buffer(INTERP, SELF, buffer);
- Parrot_gc_mark_STRING_alive(INTERP, buffer);
+ if (buffer->_bufstart)
+ mem_gc_free(INTERP, buffer->_bufstart);
+ mem_gc_free(INTERP, buffer);
}
/*
@@ -150,8 +161,11 @@
total_size = calculate_capacity(INTERP, buffer->bufused, s->bufused);
/* Reallocate if necessary */
- if (total_size > Buffer_buflen(buffer))
- Parrot_gc_reallocate_string_storage(INTERP, buffer, total_size);
+ if (total_size > Buffer_buflen(buffer)) {
+ buffer->_bufstart = buffer->strstart = mem_gc_realloc_n_typed(INTERP,
+ buffer->_bufstart, total_size, char);
+ buffer->_buflen = total_size;
+ }
/* Tack s on the end of buffer */
mem_sys_memcopy((void *)((ptrcast_t)buffer->strstart + buffer->bufused),
@@ -201,11 +215,31 @@
*/
VTABLE void set_string_native(STRING *s) {
- STRING * tmp = Parrot_str_clone(INTERP, s);
- /* Unset hashval. We update this string all the time */
- tmp->hashval = 0;
- SET_ATTR_buffer(INTERP, SELF, tmp);
+ STRING * buffer;
+
+ /* Calculate (possibly new) total size */
+ size_t total_size = calculate_capacity(INTERP, 0, s->bufused);
+
+ GET_ATTR_buffer(INTERP, SELF, buffer);
+
+ /* Reallocate if necessary */
+ if (total_size > Buffer_buflen(buffer)) {
+ buffer->_bufstart = buffer->strstart = mem_gc_realloc_n_typed(INTERP,
+ buffer->_bufstart, total_size, char);
+ buffer->_buflen = total_size;
+ }
+
+ /* Tack s on the buffer */
+ mem_sys_memcopy((void *)((ptrcast_t)buffer->strstart),
+ s->strstart, s->bufused);
+
+ /* Update buffer */
+ buffer->bufused = s->bufused;
+ buffer->strlen = Parrot_str_length(INTERP, s);
+ buffer->encoding = s->encoding;
+ buffer->charset = s->charset;
}
+
VTABLE void set_pmc(PMC *s) {
STATICSELF.set_string_native(VTABLE_get_string(INTERP, s));
}
More information about the parrot-commits
mailing list