From: kramm <kramm>
Date: Tue, 16 Nov 2004 13:57:05 +0000 (+0000)
Subject: fixed a bug which caused swf_Optimize() to miss some duplicated tags
X-Git-Tag: release-0-6-3~169
X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=9158b8afa0cd28413091347213a69349d0b8a593;p=swftools.git

fixed a bug which caused swf_Optimize() to miss some duplicated tags
due to relocating.
---

diff --git a/lib/modules/swftools.c b/lib/modules/swftools.c
index 94c440f..29b3631 100644
--- a/lib/modules/swftools.c
+++ b/lib/modules/swftools.c
@@ -966,7 +966,7 @@ static int tagHash(TAG*tag)
         a >>= 8;
         a += tag->data[t]*0xefbc35a5*b*(t+1);
     }
-    return a&0x7fffffff; //always return unsigned
+    return a&0x7fffffff; //always return positive number
 }
 
 void swf_Optimize(SWF*swf)
@@ -991,8 +991,9 @@ void swf_Optimize(SWF*swf)
            FIXME: a better way would be to compare
                   the helper tags, too.
          */
-        if(swf_isPseudoDefiningTag(tag)) {
-            //dontremap[swf_GetDefineID(tag)] = 1; //FIXME
+        if(swf_isPseudoDefiningTag(tag) &&
+           tag->id != ST_NAMECHARACTER) {
+            dontremap[swf_GetDefineID(tag)] = 1;
         }
         tag=tag->next;
     }
@@ -1001,7 +1002,22 @@ void swf_Optimize(SWF*swf)
         int doremap=1;
         
         TAG*next = tag->next;
-        
+
+        /* remap the tag */
+        int num = swf_GetNumUsedIDs(tag);
+        int*positions = rfx_alloc(sizeof(int)*num);
+        int t;
+        swf_GetUsedIDs(tag, positions);
+        for(t=0;t<num;t++) {
+            int id = GET16(&tag->data[positions[t]]);
+            id = remap[id];
+            PUT16(&tag->data[positions[t]], id);
+        }
+        rfx_free(positions);
+        tag = tag->next;
+
+        /* now look for previous tags with the same
+           content */
         if(swf_isDefiningTag(tag)) {
             TAG*tag2;
             int id = swf_GetDefineID(tag);
@@ -1050,21 +1066,6 @@ void swf_Optimize(SWF*swf)
             }
         }
 
-        if(doremap)
-        {
-            int num = swf_GetNumUsedIDs(tag);
-            int*positions = rfx_alloc(sizeof(int)*num);
-            int t;
-            swf_GetUsedIDs(tag, positions);
-            for(t=0;t<num;t++) {
-                int id = GET16(&tag->data[positions[t]]);
-                id = remap[id];
-                PUT16(&tag->data[positions[t]], id);
-            }
-            rfx_free(positions);
-            tag = tag->next;
-        }
-
         tag = next;
     }
     rfx_free(dontremap);