[svn:parrot] r48388 - branches/unshared_buffers/src/string/encoding
darbelo at svn.parrot.org
darbelo at svn.parrot.org
Tue Aug 10 21:03:21 UTC 2010
Author: darbelo
Date: Tue Aug 10 21:03:21 2010
New Revision: 48388
URL: https://trac.parrot.org/parrot/changeset/48388
Log:
Add smarter handling of constant and external strings.
Modified:
branches/unshared_buffers/src/string/encoding/fixed_8.c
branches/unshared_buffers/src/string/encoding/ucs2.c
branches/unshared_buffers/src/string/encoding/ucs4.c
branches/unshared_buffers/src/string/encoding/utf16.c
branches/unshared_buffers/src/string/encoding/utf8.c
Modified: branches/unshared_buffers/src/string/encoding/fixed_8.c
==============================================================================
--- branches/unshared_buffers/src/string/encoding/fixed_8.c Tue Aug 10 21:03:05 2010 (r48387)
+++ branches/unshared_buffers/src/string/encoding/fixed_8.c Tue Aug 10 21:03:21 2010 (r48388)
@@ -320,14 +320,22 @@
get_bytes(PARROT_INTERP, ARGIN(const STRING *src), UINTVAL offset, UINTVAL count)
{
ASSERT_ARGS(get_bytes)
- const UINTVAL flags = PObj_get_FLAGS(src) & ~PObj_external_FLAG;
+ const UINTVAL flags = PObj_get_FLAGS(src) & ~PObj_constant_FLAG;
STRING * const dst = Parrot_gc_new_string_header(interp, flags);
dst->encoding = src->encoding;
dst->charset = src->charset;
dst->bufused = dst->strlen = count;
- Parrot_gc_allocate_string_storage(interp, dst, count);
- mem_sys_memcopy(Buffer_bufstart(dst), Buffer_bufstart(src) + offset, count);
+
+ if (!(flags & PObj_external_FLAG)){
+ Parrot_gc_allocate_string_storage(interp, dst, count);
+ mem_sys_memcopy(Buffer_bufstart(dst), Buffer_bufstart(src) + offset, count);
+ }
+ else {
+ Buffer_bufstart(dst) = Buffer_bufstart(src) + offset;
+ Buffer_buflen(dst) = 0;
+ }
+
return dst;
}
Modified: branches/unshared_buffers/src/string/encoding/ucs2.c
==============================================================================
--- branches/unshared_buffers/src/string/encoding/ucs2.c Tue Aug 10 21:03:05 2010 (r48387)
+++ branches/unshared_buffers/src/string/encoding/ucs2.c Tue Aug 10 21:03:21 2010 (r48388)
@@ -314,16 +314,23 @@
{
ASSERT_ARGS(get_codepoints)
#if PARROT_HAS_ICU
- const UINTVAL flags = PObj_get_FLAGS(s) & ~PObj_external_FLAG;
+ const UINTVAL flags = PObj_get_FLAGS(s) & ~PObj_constant_FLAG;
STRING * const dst = Parrot_gc_new_string_header(interp, flags);
dst->encoding = s->encoding;
dst->charset = s->charset;
dst->strlen = count;
dst->bufused = count * sizeof (UChar);
- Parrot_gc_allocate_string_storage(interp, dst, count);
- mem_sys_memcopy(Buffer_bufstart(dst), Buffer_bufstart(s) + offs * sizeof (UChar),
- count * sizeof (UChar));
+ if (!(flags & PObj_external_FLAG)){
+ Parrot_gc_allocate_string_storage(interp, dst, count);
+ mem_sys_memcopy(Buffer_bufstart(dst), Buffer_bufstart(s) + offs * sizeof (UChar),
+ count * sizeof (UChar));
+ }
+ else {
+ Buffer_bufstart(dst) = Buffer_bufstart(s) + offs * sizeof (UChar);
+ Buffer_buflen(dst) = 0;
+ }
+
return dst;
#else
UNUSED(s);
Modified: branches/unshared_buffers/src/string/encoding/ucs4.c
==============================================================================
--- branches/unshared_buffers/src/string/encoding/ucs4.c Tue Aug 10 21:03:05 2010 (r48387)
+++ branches/unshared_buffers/src/string/encoding/ucs4.c Tue Aug 10 21:03:21 2010 (r48388)
@@ -336,17 +336,25 @@
{
ASSERT_ARGS(get_codepoints)
#if PARROT_HAS_ICU
- const UINTVAL flags = PObj_get_FLAGS(src) & ~PObj_external_FLAG;
+ const UINTVAL flags = PObj_get_FLAGS(src) & ~PObj_constant_FLAG;
STRING * const dst = Parrot_gc_new_string_header(interp, flags);
dst->encoding = src->encoding;
dst->charset = src->charset;
dst->strlen = count;
dst->bufused = count * sizeof (UChar32);
- Parrot_gc_allocate_string_storage(interp, dst, count);
- mem_sys_memcopy(Buffer_bufstart(dst),
- Buffer_bufstart(src) + offset * sizeof (UChar32),
- count * sizeof (UChar32));
+
+ if (!(flags & PObj_external_FLAG)){
+ Parrot_gc_allocate_string_storage(interp, dst, count);
+ mem_sys_memcopy(Buffer_bufstart(dst),
+ Buffer_bufstart(src) + offset * sizeof (UChar32),
+ count * sizeof (UChar32));
+ }
+ else {
+ Buffer_bufstart(dst) = Buffer_bufstart(src) + offset * sizeof (UChar32);
+ Buffer_buflen(dst) = 0;
+ }
+
return dst;
#else
UNUSED(src);
Modified: branches/unshared_buffers/src/string/encoding/utf16.c
==============================================================================
--- branches/unshared_buffers/src/string/encoding/utf16.c Tue Aug 10 21:03:05 2010 (r48387)
+++ branches/unshared_buffers/src/string/encoding/utf16.c Tue Aug 10 21:03:21 2010 (r48388)
@@ -377,7 +377,7 @@
get_codepoints(PARROT_INTERP, ARGIN(const STRING *src), UINTVAL offset, UINTVAL count)
{
ASSERT_ARGS(get_codepoints)
- const UINTVAL flags = PObj_get_FLAGS(src) & ~PObj_external_FLAG;
+ const UINTVAL flags = PObj_get_FLAGS(src) & ~PObj_constant_FLAG;
STRING * const dst = Parrot_gc_new_string_header(interp, flags);
String_iter iter;
UINTVAL start, size;
@@ -388,8 +388,15 @@
iter.set_position(interp, &iter, offset + count);
size = iter.bytepos - start;
- Parrot_gc_allocate_string_storage(interp, dst, size);
- mem_sys_memcopy(Buffer_bufstart(dst), Buffer_bufstart(src) + start, size);
+
+ if (!(flags & PObj_external_FLAG)){
+ Parrot_gc_allocate_string_storage(interp, dst, size);
+ mem_sys_memcopy(Buffer_bufstart(dst), Buffer_bufstart(src) + start, size);
+ }
+ else {
+ Buffer_bufstart(dst) = Buffer_bufstart(src) + start;
+ Buffer_buflen(dst) = 0;
+ }
dst->encoding = src->encoding;
dst->charset = src->charset;
Modified: branches/unshared_buffers/src/string/encoding/utf8.c
==============================================================================
--- branches/unshared_buffers/src/string/encoding/utf8.c Tue Aug 10 21:03:05 2010 (r48387)
+++ branches/unshared_buffers/src/string/encoding/utf8.c Tue Aug 10 21:03:21 2010 (r48388)
@@ -678,7 +678,7 @@
get_codepoints(PARROT_INTERP, ARGIN(const STRING *src), UINTVAL offset, UINTVAL count)
{
ASSERT_ARGS(get_codepoints)
- const UINTVAL flags = PObj_get_FLAGS(src) & ~PObj_external_FLAG;
+ const UINTVAL flags = PObj_get_FLAGS(src) & ~PObj_constant_FLAG;
STRING * const dst = Parrot_gc_new_string_header(interp, flags);
String_iter iter;
UINTVAL start, size;
@@ -689,8 +689,14 @@
iter.set_position(interp, &iter, offset + count);
size = iter.bytepos - start;
- Parrot_gc_allocate_string_storage(interp, dst, size);
- mem_sys_memcopy(Buffer_bufstart(dst), Buffer_bufstart(src) + start, size);
+ if (!(flags & PObj_external_FLAG)){
+ Parrot_gc_allocate_string_storage(interp, dst, size);
+ mem_sys_memcopy(Buffer_bufstart(dst), Buffer_bufstart(src) + start, size);
+ }
+ else {
+ Buffer_bufstart(dst) = Buffer_bufstart(src) + start;
+ Buffer_buflen(dst) = 0;
+ }
dst->encoding = src->encoding;
dst->charset = src->charset;
More information about the parrot-commits
mailing list