Skip Menu |

This queue is for tickets about the Font-TTF CPAN distribution.

Report information
The Basics
Id: 42872
Status: resolved
Priority: 0/
Queue: Font-TTF

People
Owner: Nobody in particular
Requestors: pjt47 [...] cam.ac.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.47



Subject: Kern::read is slow
Date: Wed, 28 Jan 2009 23:25:32 +0000
To: bug-Font-TTF [...] rt.cpan.org
From: Philip Taylor <pjt47 [...] cam.ac.uk>
This patch reduces the time taken to read the kern table of LinLibertine_Re-4.1.8.ttf from 3.7 seconds to 0.5 seconds, by greatly reducing the number of function calls involved. (This is the only place where I've found a significant bottleneck that's easily fixable. In other cases I've only got something like a 10% speedup, which doesn't seem worth bothering with.) -- Philip Taylor pjt47@cam.ac.uk
--- a/lib/Font/TTF/Kern.pm Sun Jan 25 17:47:25 2009 +0000 +++ b/lib/Font/TTF/Kern.pm Wed Jan 28 23:19:09 2009 +0000 @@ -133,12 +133,15 @@ $fh->read($dat, $len - 6); if ($t->{'Version'} == 0) { - my ($j); - $t->{'Num'} = unpack("n", $dat); - for ($j = 0; $j < $t->{'Num'}; $j++) + my @vals = unpack("n*", substr($dat, 8, $t->{'Num'} * 6)); + for (0 .. $t->{'Num'}-1) { - my ($f, $l, $v) = TTF_Unpack("SSs", substr($dat, $j * 6 + 8, 6)); + my ($f, $l, $v); + $f = shift @vals; + $l = shift @vals; + $v = shift @vals; + $v -= 65536 if $v >= 32768; $t->{'kern'}{$f}{$l} = $v; } } elsif ($t->{'Version'} == 2)
On Wed Jan 28 18:28:18 2009, pjt47@cam.ac.uk wrote: Show quoted text
> This patch reduces the time taken to read the kern table of > LinLibertine_Re-4.1.8.ttf from 3.7 seconds to 0.5 seconds, by greatly > reducing the number of function calls involved. > > (This is the only place where I've found a significant bottleneck that's > easily fixable. In other cases I've only got something like a 10% > speedup, which doesn't seem worth bothering with.) >