blob: e74d47c814e20e5a8b799da07ae346f90f88f123 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
% A small optimization package which provides
%
% \beginpgfmathparsecheckfornumber
% ...
% \endpgfmathparsecheckfornumber
%
% in order to optimize \pgfmathparse. It works as follows: inside of
% the environment (which doesn't use scopes), \pgfmathparse is
% *replaced* by a different method which uses an extremely fast check
% to decide whether the input is a number number. Is so, it returns
% the number. Otherwise, it invokes the standard math parser.
% It is about 400% faster than \pgfmathparse if the argument *is* a
% number.
%
% The \endpgfmathparsecheckfornumber is optional (no groups are
% introduced)
%
% Copyright 2010 by Christian Feuersänger.
%
% Replaces \pgfmathparse by the fast number checker.
\def\beginpgfmathparsecheckfornumber{%
\let\pgfmathparse=\pgfmathparsehashedcheck
}%
\def\endpgfmathparsecheckfornumber{%
\let\pgfmathparse=\pgfmathparsehashedcheck@orig
}%
\def\pgfmp@EOI{\pgfmp@EOI}%
\def\pgfmathparsehashedcheck@isnumber@gobble#1\pgfmp@EOI{}
\newdimen\r@pgfmathparse@hashedcheck@
\newcount\c@pgfmathparse@hashedcheck@
\let\pgfmathparsehashedcheck@orig=\pgfmathparse
\def\pgfmathparsehashedcheck#1{%
\edef\pgfmathparse@temp{#1}%
\expandafter\pgfmathparsehashedcheck@isnumber@loop\pgfmathparse@temp\pgfmp@EOI
\pgfmathparsehashedcheck@finalize{#1}%
}%
\def\pgfmathparsehashedcheck@finalize@isnonumber#1{%
\pgfmathparsehashedcheck@orig{#1}%
\let\pgfmathparsehashedcheck@finalize\pgfmathparsehashedcheck@finalize@isnumber
}%
\def\pgfmathparsehashedcheck@finalize@isnumber#1{%
\r@pgfmathparse@hashedcheck@=#1pt
\expandafter\pgfmathparsehashed@assign\the\r@pgfmathparse@hashedcheck@
%--------------------------------------------------
% %
% \let\KKK=\pgfmathresult
% \pgfmathparsehashedcheck@orig{#1}%
% \ifx\KKK\pgfmathresult
% \else
% \pgfplots@error{FAILED FOR #1: expected `\pgfmathresult'; got `\KKK' (temp = \pgf@temp)}%
% \fi
%--------------------------------------------------
}%
{\catcode`\p=12\catcode`\t=12\gdef\PGF@TEMP{pt}}
\expandafter\def\expandafter\pgfmathparsehashed@assign\expandafter#\expandafter1\expandafter.\expandafter#\expandafter2\PGF@TEMP{%
\def\pgf@temp{#2}%
\ifx\pgf@temp0%
\def\pgfmathresult{#1}%
\else
\def\pgfmathresult{#1.#2}%
\fi
}%
\let\pgfmathparsehashedcheck@finalize\pgfmathparsehashedcheck@finalize@isnumber
\expandafter\def\csname pgf@pp+\endcsname{1}
\expandafter\def\csname pgf@pp-\endcsname{1}
\expandafter\def\csname pgf@p0\endcsname{1}
\expandafter\def\csname pgf@p1\endcsname{1}
\expandafter\def\csname pgf@p2\endcsname{1}
\expandafter\def\csname pgf@p3\endcsname{1}
\expandafter\def\csname pgf@p4\endcsname{1}
\expandafter\def\csname pgf@p5\endcsname{1}
\expandafter\def\csname pgf@p6\endcsname{1}
\expandafter\def\csname pgf@p7\endcsname{1}
\expandafter\def\csname pgf@p8\endcsname{1}
\expandafter\def\csname pgf@p9\endcsname{1}
\expandafter\def\csname pgf@p.\endcsname{1}
\pgfutil@ifundefined{ifcsname}{%
\def\pgfmathparsehashedcheck@isnumber@loop#1{%
\expandafter\ifx\csname pgf@pp\string#1\endcsname\relax
\expandafter\pgfmathparsehashedcheck@isnumber@loop
\else
\expandafter\pgfmathparsehashedcheck@isnumber@loop@\expandafter#1%
\fi
}%
\def\pgfmathparsehashedcheck@isnumber@loop@#1{%
\expandafter\ifx\csname pgf@p\string#1\endcsname\relax
\expandafter\pgfmathparsehashedcheck@isnumber@loop@
\else
\expandafter\pgfmathparsehashedcheck@isnumber@endfalse\expandafter#1%
\fi
}%
}{%
\def\pgfmathparsehashedcheck@isnumber@loop#1{%
\ifcsname pgf@pp\string#1\endcsname
\expandafter\pgfmathparsehashedcheck@isnumber@loop
\else
\expandafter\pgfmathparsehashedcheck@isnumber@loop@\expandafter#1%
\fi
}%
\def\pgfmathparsehashedcheck@isnumber@loop@#1{%
\ifcsname pgf@p\string#1\endcsname
\expandafter\pgfmathparsehashedcheck@isnumber@loop@
\else
\expandafter\pgfmathparsehashedcheck@isnumber@endfalse\expandafter#1%
\fi
}%
}%
\def\pgfmathparsehashedcheck@isnumber@endfalse#1{%
\ifx#1\pgfmp@EOI
\else
\let\pgfmathparsehashedcheck@finalize=\pgfmathparsehashedcheck@finalize@isnonumber
\expandafter\pgfmathparsehashedcheck@isnumber@gobble
\fi
}%
\endinput
|