[gs-cvs] gs/lib

Ray Johnston ray at ghostscript.com
Thu Mar 3 11:05:43 PST 2005


Update of /cvs/ghostscript/gs/lib
In directory casper2:/tmp/cvs-serv17983/lib

Modified Files:
	gs_ttf.ps 
Log Message:
Eliminate a performance problem when a TT font has a large 'loca' table.
A fix for 687889 used .sort on the 'loca' table but this takes a long
time if the table is large. Only run the .sort if the table is out of
order which is rare since the TT font spec requires an in-order table.
Bug 687968.

DETAILS:

Apparently our conversion of the 'japan.ps' file creates a TT font with
a loca table that has 20458 entries (even though the original font
in japan.ps didn't have that many). This is needed because there are
many glyphs that are not present, but we need loca table slots that
represent the missing glyphs (same starting offset as next glyph).

The time was being spent doing the '{ lt } .sort' of the array  :-(

I added logic that checked the order as the loca table was converted
to an array so that the .sort could be skipped as long as the table is
in order (which it *should* be for a valid TT font). After this change,
the HEAD time is 1.16 CPU seconds versus 1.08 seconds for gs8.50.
(with the .sort, the time was 257 seconds).

I suppose that we could optimize the .sort (put it into 'C') but
for now I'll just avoid it most of the time.

Note that since the .sort has a procedure callout for the ordering test,
it might not speed up that much in 'C'. That's the other reason that it
is worthwhile to avoid the .sort when possible.



Index: gs_ttf.ps
===================================================================
RCS file: /cvs/ghostscript/gs/lib/gs_ttf.ps,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- gs_ttf.ps	1 Mar 2005 20:44:01 -0000	1.42
+++ gs_ttf.ps	3 Mar 2005 19:05:41 -0000	1.43
@@ -769,8 +769,14 @@
     /prevboundary 0 def
     % sort the locatable in case it is out of order
     % Note the 'loca' table remains unchanged
-    [ 0 1 numloca 1 sub { getloca } for ]
-    { lt } .sort	 % stack: locatable_array
+    [ /needsort false def -1	% initial values for in order check
+      0 1 numloca 1 sub {
+        getloca exch 1 index gt { /needsort true def } if dup
+      } for pop		% discard inorder check value
+    ]
+    needsort {
+      { lt } bind .sort	 % stack: locatable_array
+    } if
     /splitarray [
       3 -1 roll 0 1 numloca 1 sub {
 	% stack: /splitarray -mark- { splitlen splitlen ... } locatable_array index



More information about the gs-cvs mailing list