2 new revisions:
Revision: 6f36e2399b5b
Author: Pekka Klärck
Date: Wed Jun 8 06:40:49 2011
Log: Make sure text indices are returned as _TextIndex by storing them
in t...
http://code.google.com/p/robotframework/source/detail?r=6f36e2399b5b
Revision: d26f5c6d30d4
Author: Pekka Klärck
Date: Wed Jun 8 07:09:29 2011
Log: thresholds for compressing texts. these needs to be tuned at some
poin...
http://code.google.com/p/robotframework/source/detail?r=d26f5c6d30d4
==============================================================================
Revision: 6f36e2399b5b
Author: Pekka Klärck
Date: Wed Jun 8 06:40:49 2011
Log: Make sure text indices are returned as _TextIndex by storing them
in that format. Earlier indices were returned as an int if raw text was
already in self.texts. Tried to create a unit test for this but failed.
http://code.google.com/p/robotframework/source/detail?r=6f36e2399b5b
Modified:
/src/robot/serializing/jsparser.py
=======================================
--- /src/robot/serializing/jsparser.py Wed Jun 8 05:26:16 2011
+++ /src/robot/serializing/jsparser.py Wed Jun 8 06:40:49 2011
@@ -143,9 +143,9 @@
return self.texts[raw]
text = self._encode(text)
if text not in self.texts:
- self.texts[text] = self.index
- self.index +=1
- return _TextIndex(self.texts[text])
+ self.texts[text] = _TextIndex(self.index)
+ self.index += 1
+ return self.texts[text]
def _encode(self, text):
encoded = base64.b64encode(zlib.compress(text.encode('utf-8'), 9))
==============================================================================
Revision: d26f5c6d30d4
Author: Pekka Klärck
Date: Wed Jun 8 07:09:29 2011
Log: thresholds for compressing texts. these needs to be tuned at some
point.
http://code.google.com/p/robotframework/source/detail?r=d26f5c6d30d4
Modified:
/src/robot/serializing/jsparser.py
=======================================
--- /src/robot/serializing/jsparser.py Wed Jun 8 06:40:49 2011
+++ /src/robot/serializing/jsparser.py Wed Jun 8 07:09:29 2011
@@ -130,6 +130,9 @@
class TextCache(object):
_zero_index = _TextIndex(0)
+ # TODO: Tune compressing thresholds
+ _compress_threshold = 20
+ _use_compressed_threshold = 1.1
def __init__(self):
self.texts = {}
@@ -138,9 +141,6 @@
def add(self, text):
if not text:
return self._zero_index
- raw = self._raw(text)
- if raw in self.texts:
- return self.texts[raw]
text = self._encode(text)
if text not in self.texts:
self.texts[text] = _TextIndex(self.index)
@@ -148,9 +148,13 @@
return self.texts[text]
def _encode(self, text):
- encoded = base64.b64encode(zlib.compress(text.encode('utf-8'), 9))
raw = self._raw(text)
- return encoded if len(encoded) < len(raw) else raw
+ if raw in self.texts or len(raw) < self._compress_threshold:
+ return raw
+ compressed = base64.b64encode(zlib.compress(text.encode('UTF-8'),
9))
+ if len(raw) * self._use_compressed_threshold > len(compressed):
+ return compressed
+ return raw
def _raw(self, text):
return '*'+text