[svn:parrot] r48308 - in trunk: include/parrot src src/packfile
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Wed Aug 4 07:08:55 UTC 2010
Author: plobsing
Date: Wed Aug 4 07:08:55 2010
New Revision: 48308
URL: https://trac.parrot.org/parrot/changeset/48308
Log:
Store PMC as a simpler "buf" type in PBC in stead of full-fledged strings.
Slightly reduces PBC sizes and unpack consts.
Modified:
trunk/include/parrot/packfile.h
trunk/src/packfile.c
trunk/src/packfile/pf_items.c
trunk/src/packout.c
Modified: trunk/include/parrot/packfile.h
==============================================================================
--- trunk/include/parrot/packfile.h Wed Aug 4 05:31:18 2010 (r48307)
+++ trunk/include/parrot/packfile.h Wed Aug 4 07:08:55 2010 (r48308)
@@ -1038,6 +1038,14 @@
__attribute__nonnull__(1)
FUNC_MODIFIES(*pf);
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+STRING * PF_fetch_buf(PARROT_INTERP,
+ ARGIN_NULLOK(PackFile *pf),
+ ARGIN(const opcode_t **cursor))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(3);
+
PARROT_MALLOC
PARROT_CANNOT_RETURN_NULL
char * PF_fetch_cstring(PARROT_INTERP,
@@ -1075,6 +1083,10 @@
__attribute__nonnull__(3);
PARROT_PURE_FUNCTION
+size_t PF_size_buf(ARGIN(const STRING *s))
+ __attribute__nonnull__(1);
+
+PARROT_PURE_FUNCTION
size_t PF_size_cstring(ARGIN(const char *s))
__attribute__nonnull__(1);
@@ -1097,6 +1109,13 @@
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
+opcode_t* PF_store_buf(ARGOUT(opcode_t *cursor), ARGIN(const STRING *s))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*cursor);
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
opcode_t* PF_store_cstring(ARGOUT(opcode_t *cursor), ARGIN(const char *s))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -1132,6 +1151,9 @@
#define ASSERT_ARGS_PackFile_assign_transforms __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(pf))
+#define ASSERT_ARGS_PF_fetch_buf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(cursor))
#define ASSERT_ARGS_PF_fetch_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pf) \
@@ -1146,6 +1168,8 @@
#define ASSERT_ARGS_PF_fetch_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(cursor))
+#define ASSERT_ARGS_PF_size_buf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_PF_size_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_PF_size_integer __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
@@ -1154,6 +1178,9 @@
#define ASSERT_ARGS_PF_size_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_PF_size_strlen __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_PF_store_buf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(cursor) \
+ , PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_PF_store_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(cursor) \
, PARROT_ASSERT_ARG(s))
Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c Wed Aug 4 05:31:18 2010 (r48307)
+++ trunk/src/packfile.c Wed Aug 4 07:08:55 2010 (r48308)
@@ -3810,7 +3810,7 @@
case PFC_PMC:
component = self->u.key; /* the pmc (Sub, ...) */
- packed_size = PF_size_strlen(Parrot_freeze_pbc_size(interp, component, ct));
+ packed_size = PF_size_strlen(Parrot_freeze_pbc_size(interp, component, ct)) - 1;
break;
default:
@@ -3911,7 +3911,7 @@
/* thawing the PMC needs the real packfile in place */
PackFile_ByteCode * const cs_save = interp->code;
interp->code = pf->cur_cs;
- image = PF_fetch_string(interp, pf, &cursor);
+ image = PF_fetch_buf(interp, pf, &cursor);
pmc = Parrot_thaw_pbc(interp, image, constt);
Modified: trunk/src/packfile/pf_items.c
==============================================================================
--- trunk/src/packfile/pf_items.c Wed Aug 4 05:31:18 2010 (r48307)
+++ trunk/src/packfile/pf_items.c Wed Aug 4 07:08:55 2010 (r48308)
@@ -1189,6 +1189,104 @@
/*
+=item C<STRING * PF_fetch_buf(PARROT_INTERP, PackFile *pf, const opcode_t
+**cursor)>
+
+Fetches a buffer (fixed_8 encoded temporary C<STRING>) from bytecode.
+
+Opcode format is:
+
+ opcode_t size
+ * data
+
+When used for freeze/thaw, the C<pf> argument might be C<NULL>.
+
+The returned buffer points to the underlying packfile. It should be used and
+discarded immediately to avoid things changing underneath you.
+
+=cut
+
+*/
+
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+STRING *
+PF_fetch_buf(PARROT_INTERP, ARGIN_NULLOK(PackFile *pf), ARGIN(const opcode_t **cursor))
+{
+ const int wordsize = pf ? pf->header->wordsize : sizeof (opcode_t);
+ size_t size = PF_fetch_opcode(pf, cursor);
+ STRING *s = Parrot_str_new_init(interp, (const char *)*cursor, size,
+ Parrot_fixed_8_encoding_ptr, Parrot_binary_charset_ptr,
+ PObj_external_FLAG);
+ *((const unsigned char **)(cursor)) += ROUND_UP_B(size, wordsize);
+ return s;
+}
+
+
+/*
+
+=item C<opcode_t* PF_store_buf(opcode_t *cursor, const STRING *s)>
+
+Write a buffer (fixed_8 encoded, binary string) to the opcode stream. These
+are encoded more compactly and read more efficiently than normal strings, but
+have limitations (see C<PF_fetch_buf>).
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+opcode_t*
+PF_store_buf(ARGOUT(opcode_t *cursor), ARGIN(const STRING *s))
+{
+ const int wordsize = sizeof (opcode_t);
+
+ PARROT_ASSERT(s->encoding == Parrot_fixed_8_encoding_ptr);
+ PARROT_ASSERT(s->charset == Parrot_binary_charset_ptr);
+
+ *cursor++ = s->bufused;
+
+ if (s->strstart) {
+ char *charcursor = (char *) cursor;
+ mem_sys_memcopy(charcursor, s->strstart, s->bufused);
+ charcursor += s->bufused;
+
+ /* Pad up to wordsize boundary. */
+ while ((charcursor - (char *)cursor) % wordsize)
+ *charcursor++ = 0;
+
+ cursor += (charcursor - (char *)cursor) / wordsize;
+ }
+
+ return cursor;
+}
+
+
+/*
+
+=item C<size_t PF_size_buf(const STRING *s)>
+
+Reports the stored size of a buffer in C<opcode_t> units.
+
+=cut
+
+*/
+
+PARROT_PURE_FUNCTION
+size_t
+PF_size_buf(ARGIN(const STRING *s))
+{
+ if (STRING_IS_NULL(s))
+ return 1;
+ else
+ return PF_size_strlen(s->bufused) - 1;
+}
+
+
+/*
+
=item C<STRING * PF_fetch_string(PARROT_INTERP, PackFile *pf, const opcode_t
**cursor)>
Modified: trunk/src/packout.c
==============================================================================
--- trunk/src/packout.c Wed Aug 4 05:31:18 2010 (r48307)
+++ trunk/src/packout.c Wed Aug 4 07:08:55 2010 (r48308)
@@ -361,9 +361,9 @@
break;
case PFC_PMC:
- key = self->u.key; /* the (Sub) PMC */
- image = Parrot_freeze_pbc(interp, key, const_table);
- cursor = PF_store_string(cursor, image);
+ key = self->u.key; /* the (Sub) PMC */
+ image = Parrot_freeze_pbc(interp, key, const_table);
+ cursor = PF_store_buf(cursor, image);
break;
case PFC_KEY:
More information about the parrot-commits
mailing list