[svn:parrot] r45925 - in trunk: include/parrot src

NotFound at svn.parrot.org NotFound at svn.parrot.org
Thu Apr 22 20:47:29 UTC 2010


Author: NotFound
Date: Thu Apr 22 20:47:29 2010
New Revision: 45925
URL: https://trac.parrot.org/parrot/changeset/45925

Log:
allocate pir debug mappings as array of structs, instead of array of pointers to structs

Modified:
   trunk/include/parrot/packfile.h
   trunk/src/embed.c
   trunk/src/packfile.c
   trunk/src/pbc_merge.c

Modified: trunk/include/parrot/packfile.h
==============================================================================
--- trunk/include/parrot/packfile.h	Thu Apr 22 20:46:10 2010	(r45924)
+++ trunk/include/parrot/packfile.h	Thu Apr 22 20:47:29 2010	(r45925)
@@ -270,7 +270,7 @@
 typedef struct PackFile_Debug {
     PackFile_Segment        base;
     opcode_t                num_mappings;
-    PackFile_DebugFilenameMapping **mappings;
+    PackFile_DebugFilenameMapping *mappings;
     PackFile_ByteCode      *code;   /* where this segment belongs to */
 } PackFile_Debug;
 

Modified: trunk/src/embed.c
==============================================================================
--- trunk/src/embed.c	Thu Apr 22 20:46:10 2010	(r45924)
+++ trunk/src/embed.c	Thu Apr 22 20:47:29 2010	(r45925)
@@ -1001,12 +1001,12 @@
 
         /* Parrot_io_fprintf(interp, output, "%i < %i %i == %i \n", curr_mapping,
          * num_mappings, op_code_seq_num,
-         * interp->code->debugs->mappings[curr_mapping]->offset); */
+         * interp->code->debugs->mappings[curr_mapping].offset); */
 
         if (debugs && curr_mapping < num_mappings) {
-            if (op_code_seq_num == interp->code->debugs->mappings[curr_mapping]->offset) {
+            if (op_code_seq_num == interp->code->debugs->mappings[curr_mapping].offset) {
                 const int filename_const_offset =
-                    interp->code->debugs->mappings[curr_mapping]->filename;
+                    interp->code->debugs->mappings[curr_mapping].filename;
                 Parrot_io_fprintf(interp, output, "# Current Source Filename '%Ss'\n",
                         interp->code->const_table->constants[filename_const_offset]->u.string);
                 curr_mapping++;

Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c	Thu Apr 22 20:46:10 2010	(r45924)
+++ trunk/src/packfile.c	Thu Apr 22 20:47:29 2010	(r45925)
@@ -2641,11 +2641,6 @@
 {
     ASSERT_ARGS(pf_debug_destroy)
     PackFile_Debug * const debug = (PackFile_Debug *) self;
-    int i;
-
-    /* Free each mapping. */
-    for (i = 0; i < debug->num_mappings; i++)
-        mem_gc_free(interp, debug->mappings[i]);
 
     /* Free mappings pointer array. */
     mem_gc_free(interp, debug->mappings);
@@ -2729,8 +2724,8 @@
     /* Now store each mapping. */
     for (i = 0; i < n; i++) {
         /* Bytecode offset and filename. */
-        *cursor++ = debug->mappings[i]->offset;
-        *cursor++ = debug->mappings[i]->filename;
+        *cursor++ = debug->mappings[i].offset;
+        *cursor++ = debug->mappings[i].filename;
     }
 
     return cursor;
@@ -2770,15 +2765,13 @@
 
     /* Allocate space for mappings vector. */
     debug->mappings = mem_gc_allocate_n_zeroed_typed(interp,
-            debug->num_mappings + 1, PackFile_DebugFilenameMapping *);
+            debug->num_mappings + 1, PackFile_DebugFilenameMapping);
 
     /* Read in each mapping. */
     for (i = 0; i < debug->num_mappings; i++) {
-        /* Allocate struct and get offset and filename type. */
-        debug->mappings[i]           =
-                mem_gc_allocate_zeroed_typed(interp, PackFile_DebugFilenameMapping);
-        debug->mappings[i]->offset   = PF_fetch_opcode(self->pf, &cursor);
-        debug->mappings[i]->filename = PF_fetch_opcode(self->pf, &cursor);
+        /* Get offset and filename type. */
+        debug->mappings[i].offset   = PF_fetch_opcode(self->pf, &cursor);
+        debug->mappings[i].filename = PF_fetch_opcode(self->pf, &cursor);
     }
 
     /* find seg e.g. CODE_DB => CODE and attach it */
@@ -2823,9 +2816,9 @@
     for (i = 0; i < debug->num_mappings; i++) {
         Parrot_io_printf(interp, "    #%d\n    [\n", i);
         Parrot_io_printf(interp, "        OFFSET => %d,\n",
-                   debug->mappings[i]->offset);
+                   debug->mappings[i].offset);
         Parrot_io_printf(interp, "        FILENAME => %Ss\n",
-                PF_CONST(debug->code, debug->mappings[i]->filename)->u.string);
+                PF_CONST(debug->code, debug->mappings[i].filename)->u.string);
         Parrot_io_printf(interp, "    ],\n");
     }
 
@@ -2908,7 +2901,7 @@
 
     /* If the previous mapping has the same filename, don't record it. */
     if (debug->num_mappings) {
-        prev_filename_n = debug->mappings[debug->num_mappings-1]->filename;
+        prev_filename_n = debug->mappings[debug->num_mappings-1].filename;
         filename_pstr = Parrot_str_new(interp, filename, 0);
         if (ct->constants[prev_filename_n]->type == PFC_STRING &&
                 Parrot_str_equal(interp, filename_pstr,
@@ -2920,18 +2913,18 @@
     /* Allocate space for the extra entry. */
     debug->mappings = mem_gc_realloc_n_typed(interp,
             debug->mappings, debug->num_mappings + 1,
-            PackFile_DebugFilenameMapping *);
+            PackFile_DebugFilenameMapping);
 
     /* Can it just go on the end? */
     if (debug->num_mappings == 0
-    ||  offset              >= debug->mappings[debug->num_mappings - 1]->offset)
+    ||  offset              >= debug->mappings[debug->num_mappings - 1].offset)
         insert_pos = debug->num_mappings;
     else {
         /* Find the right place and shift stuff that's after it. */
         int i;
 
         for (i = 0; i < debug->num_mappings; i++) {
-            if (debug->mappings[i]->offset > offset) {
+            if (debug->mappings[i].offset > offset) {
                 insert_pos = i;
                 memmove(debug->mappings + i + 1, debug->mappings + i,
                     debug->num_mappings - i);
@@ -2943,14 +2936,13 @@
     /* Need to put filename in constants table. */
     {
         /* Set up new entry and insert it. */
-        PackFile_DebugFilenameMapping *mapping =
-                mem_gc_allocate_zeroed_typed(interp, PackFile_DebugFilenameMapping);
+        PackFile_DebugFilenameMapping *mapping = debug->mappings + insert_pos;
         STRING *namestr = Parrot_str_new_init(interp, filename, strlen(filename),
                 PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET, 0);
         size_t count = ct->const_count;
         size_t i;
 
-        mapping->offset       = offset;
+        mapping->offset = offset;
 
         /* Check if there is already a constant with this filename */
         for (i= 0; i < count; ++i) {
@@ -2978,8 +2970,7 @@
         }
 
         /* Set the mapped value */
-        mapping->filename     = count;
-        debug->mappings[insert_pos] = mapping;
+        mapping->filename = count;
         debug->num_mappings         = debug->num_mappings + 1;
     }
 }
@@ -3012,10 +3003,10 @@
         /* If this is the last mapping or the current position is
            between this mapping and the next one, return a filename. */
        if (i + 1                          == debug->num_mappings
-       || (debug->mappings[i]->offset     <= pc
-       &&  debug->mappings[i + 1]->offset >  pc))
+       || (debug->mappings[i].offset     <= pc
+       &&  debug->mappings[i + 1].offset >  pc))
             return PF_CONST(debug->code,
-                    debug->mappings[i]->filename)->u.string;
+                    debug->mappings[i].filename)->u.string;
     }
 
     /* Otherwise, no mappings == no filename. */

Modified: trunk/src/pbc_merge.c
==============================================================================
--- trunk/src/pbc_merge.c	Thu Apr 22 20:46:10 2010	(r45924)
+++ trunk/src/pbc_merge.c	Thu Apr 22 20:47:29 2010	(r45925)
@@ -566,8 +566,8 @@
     PackFile_Debug                 *debug_seg;
     opcode_t                       *lines    = mem_gc_allocate_typed(interp,
                                                 opcode_t);
-    PackFile_DebugFilenameMapping **mappings =
-        mem_gc_allocate_typed(interp, PackFile_DebugFilenameMapping *);
+    PackFile_DebugFilenameMapping *mappings =
+        mem_gc_allocate_typed(interp, PackFile_DebugFilenameMapping);
 
     opcode_t num_mappings = 0;
     opcode_t num_lines    = 0;
@@ -591,16 +591,14 @@
         /* Concatenate mappings. */
         mappings = mem_gc_realloc_n_typed(interp, mappings,
                 num_mappings + in_seg->num_mappings,
-                PackFile_DebugFilenameMapping*);
+                PackFile_DebugFilenameMapping);
 
         for (j = 0; j < in_seg->num_mappings; j++) {
-            PackFile_DebugFilenameMapping * const mapping =
-                mem_gc_allocate_typed(interp, PackFile_DebugFilenameMapping);
+            PackFile_DebugFilenameMapping *mapping = mappings + num_mappings + j;
 
-            STRUCT_COPY(mapping, in_seg->mappings[j]);
+            STRUCT_COPY_FROM_STRUCT(mapping, in_seg->mappings[j]);
             mapping->offset   += num_lines;
             mapping->filename += inputs[i]->const_start;
-            mappings[num_mappings + j] = mapping;
         }
 
         num_lines    += in_seg->base.size - 1;


More information about the parrot-commits mailing list