Bug 1438700, part 2 - Deduplicate XPT strings. r=glandium

Various strings, like nsISupports, appear many times in XPT data. This
patch adds a cache so we don't write the same string multiple times.

MozReview-Commit-ID: 6buBrXwHqQz

--HG--
extra : rebase_source : 54dea83a9134710c5600828ab68ef3f935f46afd
This commit is contained in:
Andrew McCreight 2018-02-15 15:41:05 -08:00
parent b553286f4a
commit a106e111fe

View File

@ -577,10 +577,14 @@ class CachedStringWriter(object):
def __init__(self, file, data_pool_offset):
self.file = file
self.data_pool_offset = data_pool_offset
self.names = {}
def write(self, s):
if s:
if s in self.names:
return self.names[s]
offset = self.file.tell() - self.data_pool_offset + 1
self.names[s] = offset
self.file.write(s + "\x00")
return offset
else: