Skip to content

Commit

Permalink
[pmc] Avoid StringBuilder copies on set_pmc, ...
Browse files Browse the repository at this point in the history
and push_pmc, i_concatenate, when the arg is a StringBuilder
PMC already. 0.5% faster.
  • Loading branch information
Reini Urban committed Jan 23, 2015
1 parent 4d66f6c commit 9cf2c34
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/pmc/stringbuilder.pmc
Expand Up @@ -269,11 +269,25 @@ Append string. Synonym for push_string
}

VTABLE void i_concatenate(PMC *p) :manual_wb {
STATICSELF.push_string(VTABLE_get_string(INTERP, p));
if (p->vtable->base_type == enum_class_StringBuilder) {
STRING *buffer;
GET_ATTR_buffer(INTERP, p, buffer);
STATICSELF.push_string(buffer);
}
else {
STATICSELF.push_string(VTABLE_get_string(INTERP, p));
}
}

VTABLE void push_pmc(PMC *p) :manual_wb {
STATICSELF.push_string(VTABLE_get_string(INTERP, p));
if (p->vtable->base_type == enum_class_StringBuilder) {
STRING *buffer;
GET_ATTR_buffer(INTERP, p, buffer);
STATICSELF.push_string(buffer);
}
else {
STATICSELF.push_string(VTABLE_get_string(INTERP, p));
}
}

/*
Expand Down Expand Up @@ -312,7 +326,14 @@ Set content of buffer to passed string or PMC
}

VTABLE void set_pmc(PMC *s) :manual_wb {
STATICSELF.set_string_native(VTABLE_get_string(INTERP, s));
if (s->vtable->base_type == enum_class_StringBuilder) {
STRING *buffer;
GET_ATTR_buffer(INTERP, s, buffer);
STATICSELF.push_string(buffer);
}
else {
STATICSELF.set_string_native(VTABLE_get_string(INTERP, s));
}
}


Expand Down

0 comments on commit 9cf2c34

Please sign in to comment.