Gitweb links:

...log 
http://git.netsurf-browser.org/libcss.git/shortlog/41cee64272bed090f3b2151ce00b00c3c89222f1
...commit 
http://git.netsurf-browser.org/libcss.git/commit/41cee64272bed090f3b2151ce00b00c3c89222f1
...tree 
http://git.netsurf-browser.org/libcss.git/tree/41cee64272bed090f3b2151ce00b00c3c89222f1

The branch, lcneves/units has been updated
       via  41cee64272bed090f3b2151ce00b00c3c89222f1 (commit)
      from  ae14e8b9dd656a59d1013b977b8e2057825624b7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/libcss.git/commit/?id=41cee64272bed090f3b2151ce00b00c3c89222f1
commit 41cee64272bed090f3b2151ce00b00c3c89222f1
Author: Lucas Neves <[email protected]>
Commit: Lucas Neves <[email protected]>

    WIP: Select: autogen for selection properties.

diff --git a/src/select/assets.py b/src/select/assets.py
index 1d726a3..33982b0 100644
--- a/src/select/assets.py
+++ b/src/select/assets.py
@@ -3,10 +3,7 @@
 # http://www.opensource.org/licenses/mit-license.php
 # Copyright 2017 Lucas Neves <[email protected]>
 
-assets = {}
-
-assets['computed.h'] = {}
-assets['computed.h']['header'] = '''\
+copyright = '''\
 /*
  * This file is part of LibCSS
  * Licensed under the MIT License,
@@ -14,6 +11,12 @@ assets['computed.h']['header'] = '''\
  * Copyright 2017 The NetSurf Project
  */
 
+'''
+
+assets = {}
+
+assets['computed.h'] = {}
+assets['computed.h']['header'] = copyright + '''\
 #ifndef css_select_computed_h_
 #define css_select_computed_h_
 
diff --git a/src/select/select_generator.py b/src/select/select_generator.py
index 3e6744c..a1af7a5 100644
--- a/src/select/select_generator.py
+++ b/src/select/select_generator.py
@@ -6,17 +6,6 @@
 from select_config import values, groups
 from assets import assets
 
-class Bin:
-    def __init__(self, first_object):
-        self.contents = [ first_object ]
-
-    @property
-    def size(self):
-        return sum([ x['size'] for x in self.contents ])
-
-    def push(self, obj):
-        self.contents.append(obj)
-
 class Text:
     def __init__(self):
         self._lines = []
@@ -137,32 +126,48 @@ class CSSProperty:
         return (name + bits_size + vars_size +
                 (' + ' if vars_size and ptr else '') + ptr)
 
+class Bin:
+    def __init__(self, first_object):
+        self.contents = [ first_object ]
+
+    @property
+    def size(self):
+        return sum([ x['size'] for x in self.contents ])
+
+    def push(self, obj):
+        self.contents.append(obj)
+
 class CSSGroup:
     def __init__(self, config, is_main=False):
         self.name = config['name']
         self.props = [ CSSProperty(*x) for x in config['props'] ]
         self.is_main = is_main
+        self.__bits_array = None
 
     @property
-    def bit_map(self):
+    def bits_array(self):
         '''Implements a `best fit first` heuristics for the bin packing of
         property bits in the bits array'''
 
+        if self.__bits_array is not None:
+            return self.__bits_array
+
         bin_size = 32
-        bit_map = []
+        self.__bits_array = []
         props = sorted([ { 'name': p.name, 'size': p.bits_size }
             for p in self.props ], key=(lambda x: x['size']), reverse=True)
 
         for p in props:
-            for b in bit_map:
+            for b in self.__bits_array:
                 if b.size + p['size'] <= bin_size:
                     b.push(p)
                     break
             else:
-                bit_map.append(Bin(p))
-            bit_map.sort(key=(lambda x: x.size), reverse=True)
+                self.__bits_array.append(Bin(p))
+
+            self.__bits_array.sort(key=(lambda x: x.size), reverse=True)
 
-        return bit_map
+        return self.__bits_array
 
     def make_computed_h(self):
         t = Text()
@@ -179,15 +184,12 @@ class CSSGroup:
         else:
             raise ValueError()
 
-def write_file(self, filename, data):
-        self._lines.append('')
-
 css_groups = [ CSSGroup(g) for g in groups['others'] ]
 css_groups.append(CSSGroup(groups['main'], is_main=True))
-files = ['computed.h']
 
-for f in files:
-    body = '\n'.join([ x.make_text(f) for x in css_groups ])
-    text = '\n'.join([ assets[f]['header'], body, assets[f]['footer'] ])
-    with open('autogenerated_' + f, 'w') as file_f:
-        file_f.write(text)
+for k, v in assets:
+    # Key is filename string (e.g. "computed.h") without autogenerated_ prefix
+    body = '\n'.join([ g.make_text(k) for g in css_groups ])
+    text = '\n'.join([ v['header'], body, v['footer'] ])
+    with open('autogenerated_' + k, 'w') as file_k:
+        file_k.write(text)


-----------------------------------------------------------------------

Summary of changes:
 src/select/assets.py           |   11 +++++---
 src/select/select_generator.py |   54 +++++++++++++++++++++-------------------
 2 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/src/select/assets.py b/src/select/assets.py
index 1d726a3..33982b0 100644
--- a/src/select/assets.py
+++ b/src/select/assets.py
@@ -3,10 +3,7 @@
 # http://www.opensource.org/licenses/mit-license.php
 # Copyright 2017 Lucas Neves <[email protected]>
 
-assets = {}
-
-assets['computed.h'] = {}
-assets['computed.h']['header'] = '''\
+copyright = '''\
 /*
  * This file is part of LibCSS
  * Licensed under the MIT License,
@@ -14,6 +11,12 @@ assets['computed.h']['header'] = '''\
  * Copyright 2017 The NetSurf Project
  */
 
+'''
+
+assets = {}
+
+assets['computed.h'] = {}
+assets['computed.h']['header'] = copyright + '''\
 #ifndef css_select_computed_h_
 #define css_select_computed_h_
 
diff --git a/src/select/select_generator.py b/src/select/select_generator.py
index 3e6744c..a1af7a5 100644
--- a/src/select/select_generator.py
+++ b/src/select/select_generator.py
@@ -6,17 +6,6 @@
 from select_config import values, groups
 from assets import assets
 
-class Bin:
-    def __init__(self, first_object):
-        self.contents = [ first_object ]
-
-    @property
-    def size(self):
-        return sum([ x['size'] for x in self.contents ])
-
-    def push(self, obj):
-        self.contents.append(obj)
-
 class Text:
     def __init__(self):
         self._lines = []
@@ -137,32 +126,48 @@ class CSSProperty:
         return (name + bits_size + vars_size +
                 (' + ' if vars_size and ptr else '') + ptr)
 
+class Bin:
+    def __init__(self, first_object):
+        self.contents = [ first_object ]
+
+    @property
+    def size(self):
+        return sum([ x['size'] for x in self.contents ])
+
+    def push(self, obj):
+        self.contents.append(obj)
+
 class CSSGroup:
     def __init__(self, config, is_main=False):
         self.name = config['name']
         self.props = [ CSSProperty(*x) for x in config['props'] ]
         self.is_main = is_main
+        self.__bits_array = None
 
     @property
-    def bit_map(self):
+    def bits_array(self):
         '''Implements a `best fit first` heuristics for the bin packing of
         property bits in the bits array'''
 
+        if self.__bits_array is not None:
+            return self.__bits_array
+
         bin_size = 32
-        bit_map = []
+        self.__bits_array = []
         props = sorted([ { 'name': p.name, 'size': p.bits_size }
             for p in self.props ], key=(lambda x: x['size']), reverse=True)
 
         for p in props:
-            for b in bit_map:
+            for b in self.__bits_array:
                 if b.size + p['size'] <= bin_size:
                     b.push(p)
                     break
             else:
-                bit_map.append(Bin(p))
-            bit_map.sort(key=(lambda x: x.size), reverse=True)
+                self.__bits_array.append(Bin(p))
+
+            self.__bits_array.sort(key=(lambda x: x.size), reverse=True)
 
-        return bit_map
+        return self.__bits_array
 
     def make_computed_h(self):
         t = Text()
@@ -179,15 +184,12 @@ class CSSGroup:
         else:
             raise ValueError()
 
-def write_file(self, filename, data):
-        self._lines.append('')
-
 css_groups = [ CSSGroup(g) for g in groups['others'] ]
 css_groups.append(CSSGroup(groups['main'], is_main=True))
-files = ['computed.h']
 
-for f in files:
-    body = '\n'.join([ x.make_text(f) for x in css_groups ])
-    text = '\n'.join([ assets[f]['header'], body, assets[f]['footer'] ])
-    with open('autogenerated_' + f, 'w') as file_f:
-        file_f.write(text)
+for k, v in assets:
+    # Key is filename string (e.g. "computed.h") without autogenerated_ prefix
+    body = '\n'.join([ g.make_text(k) for g in css_groups ])
+    text = '\n'.join([ v['header'], body, v['footer'] ])
+    with open('autogenerated_' + k, 'w') as file_k:
+        file_k.write(text)


-- 
Cascading Style Sheets library

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to