From 9edcc95c81a13788b02b96a3442a8c9734279ab8 Mon Sep 17 00:00:00 2001 From: niv Date: Tue, 1 May 2012 23:37:44 +0200 Subject: [PATCH] erf handling: fix performance bottleneck when loading large erf files --- lib/nwn/erf.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/nwn/erf.rb b/lib/nwn/erf.rb index b7d5d33..f20cd9d 100644 --- a/lib/nwn/erf.rb +++ b/lib/nwn/erf.rb @@ -133,12 +133,12 @@ def write_to io [c.resref, @content.index(c), c.res_type, 0].pack("a#{fnlen} V v v") }.join("") - pre_offset = 160 + locstr.size + keylist.size + 8 * @content.size + offset = 160 + locstr.size + keylist.size + 8 * @content.size reslist = @content.map {|c| - offset = pre_offset + - @content[0, @content.index(c)].inject(0) {|sum,x| sum + x.size } - [offset, c.size].pack("V V") + r = [offset, c.size].pack("V V") + offset += c.size + r }.join("") offset_to_locstr = 160