The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Fix a performance issue connected to multimasters

These changes was commited to the Birdfont repository Sun, 13 Dec 2015 11:36:41 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 13 Dec 2015 11:36:41 +0000 (12:36 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 13 Dec 2015 15:07:18 +0000 (16:07 +0100)
commit da4b696ea947787c305bb5189d68f159d25a7c79
tree 2fa25a8845f22dc4dc897645f77ec9a921a1d1e4
parent 03674b2c0521cfc79884047808d15c3b7f9edf54
Fix a performance issue connected to multimasters

libbirdfont/GlyphCollection.vala
--- a/libbirdfont/GlyphCollection.vala +++ b/libbirdfont/GlyphCollection.vala @@ -68,8 +68,11 @@ i = glyph_masters.size - 1; } - return_val_if_fail (0 <= i < glyph_masters.size, new GlyphMaster ()); - + if (unlikely (!(0 <= i < glyph_masters.size))) { + warning(@"index out of bounds $i"); + return new GlyphMaster (); + } + return glyph_masters.get (i); } @@ -84,14 +87,20 @@ } public GlyphMaster get_master (string id) { + GlyphMaster? found = null; + foreach (GlyphMaster m in glyph_masters) { if (m.get_id () == id) { - return m; + found = m; } } - warning ("Master not found for id $(id)."); - return new GlyphMaster (); + if (unlikely (found == null)) { + warning ("Master not found for id $(id)."); + return new GlyphMaster (); + } + + return (!) found; } public bool is_multimaster() { @@ -121,7 +130,7 @@ public void set_selected_master (GlyphMaster m) { current_master = glyph_masters.index_of (m); - if (current_master == -1) { + if (unlikely (current_master == -1)) { warning ("Master does not exits"); current_master = 0; }