[XeTeX] Performance of ucharclasses

Bruno Le Floch blflatex at gmail.com
Sat Oct 22 21:14:22 CEST 2011


Hello all,

Loading the ucharclasses package with no option is extremely slow (>
2min on my installation), because it loads every Unicode block (as
documented).

The performance can be significantly improved by using lower-level
code for the loops. For instance, using the following helper macro
(not quite optimized for speed, because I wanted to remain reasonably
close to the original \forloop syntax):

    \newcommand{\@ucc at forloop}[1]
      {\expandafter\@ucc at forloop@\csname c@#1\endcsname}
    \newcommand{\@ucc at forloop@}[4]{%
      #1=#2\relax
      \loop
        #4\relax
      \ifnum#1<#3\relax
        \advance#1 by \@ne
      \repeat
    }

we can replace the definition of `\@defineUnicodeClass` by

    \newcounter{glyphcounter}
    \newcommand{\@defineUnicodeClass}[3]{%
      \newXeTeXintercharclass#1
      \@ucc at forloop {glyphcounter}{#2}{#3}
       {\XeTeXcharclass\value{glyphcounter}=#1}
   }

(in other words, change the \forloop line). All other \forloop can be
replaced in a similar way, giving rise to a 10 fold speed improvement
at least.

This post stems from an [answer I gave on the TeX.stackexchange
network](http://tex.stackexchange.com/questions/32351/is-there-a-way-to-speed-up-the-use-of-ucharclasses/32379#32379).
Is that answer "legal", given the license of the package, or should I
delete it?

Regards,
Bruno


More information about the XeTeX mailing list