[pypy-svn] r28805 - in pypy/dist/pypy/translator/js/proxy/testme: . static/javascript

ericvrp at codespeak.net ericvrp at codespeak.net
Thu Jun 15 13:14:32 CEST 2006


Author: ericvrp
Date: Thu Jun 15 13:14:31 2006
New Revision: 28805

Modified:
   pypy/dist/pypy/translator/js/proxy/testme/controllers.py
   pypy/dist/pypy/translator/js/proxy/testme/servermessage.py
   pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js
Log:
optimization by returning only the last of all available inline frames


Modified: pypy/dist/pypy/translator/js/proxy/testme/controllers.py
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/controllers.py	(original)
+++ pypy/dist/pypy/translator/js/proxy/testme/controllers.py	Thu Jun 15 13:14:31 2006
@@ -6,7 +6,7 @@
 import socket
 import urllib
 import re
-from servermessage import ServerMessage, log
+from servermessage import ServerMessage, log, PMSG_INLINE_FRAME
 from random import random
 from md5 import md5
 
@@ -74,10 +74,15 @@
         sm.data = data
         #log('RECEIVED DATA REMAINING CONTAINS %d BYTES' % len(data))
 
-        #XXX: TODO: remove all but the last message where type == 'inline_frame'(PMSG_INLINE_FRAME)
+        len_before = len(messages)
+        #XXX we could do better by not generating only the last inline_frame message anyway!
+        inline_frames = [i for i,msg in enumerate(messages) if msg['type'] == PMSG_INLINE_FRAME]
+        for i in reversed(inline_frames[:-1]):
+            del messages[i]
 
         #if messages:
-        #    log('MESSAGES:%s' % messages)
+        #    log('MESSAGES:lenbefore=%d, inline_frames=%s, lenafter=%d' % (
+        #        len_before, inline_frames, len(messages)))
         return dict(messages=messages)
 
     def _close(self):

Modified: pypy/dist/pypy/translator/js/proxy/testme/servermessage.py
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/servermessage.py	(original)
+++ pypy/dist/pypy/translator/js/proxy/testme/servermessage.py	Thu Jun 15 13:14:31 2006
@@ -2,7 +2,7 @@
 from cherrypy import session
 from msgstruct import *
 import PIL.Image
-from zlib import decompressobj
+from zlib import decompressobj, decompress
 from urllib import quote
 from os import mkdir
 from os.path import exists
@@ -96,7 +96,7 @@
         else:
             bitmap_filename = '%sbitmap%d.ppm' % (self.gfx_dir, bitmap_code)
             try:
-                decompressed_data = self.decompressobj(data)
+                decompressed_data = decompress(data)
             except Exception, e:
                 raise BitmapCreationException('ERROR UNCOMPRESSING DATA FOR %s (%s)' % (
                     bitmap_filename, str(e)))
@@ -200,8 +200,8 @@
 
     def inline_frame(self, data):
         decompressed_data = d = self.decompressobj(data)
-        log('inline_frame len(data)=%d, len(decompressed_data)=%d' % (
-            len(data), len(d)))
+        #log('inline_frame len(data)=%d, len(decompressed_data)=%d' % (
+        #    len(data), len(d)))
 
         return_raw_data = False
         if return_raw_data:

Modified: pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js	(original)
+++ pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js	Thu Jun 15 13:14:31 2006
@@ -54,11 +54,12 @@
                 //    reuse what's already attached to the playfield.
                 //    On the other hand this might not be bad and communication overhead
                 //    seems to be the killer anyway.
-                var img = IMG({'src':icon[icon_code].filename,
-                'width':icon[icon_code].width, 'height':icon[icon_code].height,
-                'style':'position:absolute; top:' + y + 'px; left:' + x + 'px;'});
-
-                images.push(img);
+                if (icon_code in icon) {
+                    var img = IMG({'src':icon[icon_code].filename,
+                        'width':icon[icon_code].width, 'height':icon[icon_code].height,
+                        'style':'position:absolute; top:' + y + 'px; left:' + x + 'px;'});
+                    images.push(img);
+                }
             }
             replaceChildNodes(playfield, images);
         }



More information about the Pypy-commit mailing list