tools/qstringmatcher.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3static void bm_init_skiptable(const ushort *uc, int len, uchar *skiptable, Qt::CaseSensitivity cs) -
4{ -
5 int l = qMin(len, 255); -
6 memset(skiptable, l, 256*sizeof(uchar)); -
7 uc += len - l; -
8 if (cs == Qt::CaseSensitive) {
evaluated: cs == Qt::CaseSensitive
TRUEFALSE
yes
Evaluation Count:363274
yes
Evaluation Count:196
196-363274
9 while (l--) {
evaluated: l--
TRUEFALSE
yes
Evaluation Count:4402100
yes
Evaluation Count:362450
362450-4402100
10 skiptable[*uc & 0xff] = l; -
11 uc++; -
12 }
executed: }
Execution Count:4402031
4402031
13 } else {
executed: }
Execution Count:362157
362157
14 const ushort *start = uc; -
15 while (l--) {
evaluated: l--
TRUEFALSE
yes
Evaluation Count:6258
yes
Evaluation Count:196
196-6258
16 skiptable[foldCase(uc, start) & 0xff] = l; -
17 uc++; -
18 }
executed: }
Execution Count:6258
6258
19 }
executed: }
Execution Count:196
196
20} -
21 -
22static inline int bm_find(const ushort *uc, uint l, int index, const ushort *puc, uint pl, -
23 const uchar *skiptable, Qt::CaseSensitivity cs) -
24{ -
25 if (pl == 0)
evaluated: pl == 0
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:366322
34-366322
26 return index > (int)l ? -1 : index;
executed: return index > (int)l ? -1 : index;
Execution Count:34
34
27 const uint pl_minus_one = pl - 1; -
28 -
29 register const ushort *current = uc + index + pl_minus_one; -
30 const ushort *end = uc + l; -
31 if (cs == Qt::CaseSensitive) {
evaluated: cs == Qt::CaseSensitive
TRUEFALSE
yes
Evaluation Count:365099
yes
Evaluation Count:1596
1596-365099
32 while (current < end) {
evaluated: current < end
TRUEFALSE
yes
Evaluation Count:34448589
yes
Evaluation Count:56502
56502-34448589
33 uint skip = skiptable[*current & 0xff]; -
34 if (!skip) {
evaluated: !skip
TRUEFALSE
yes
Evaluation Count:214917
yes
Evaluation Count:34619319
214917-34619319
35 -
36 while (skip < pl) {
evaluated: skip < pl
TRUEFALSE
yes
Evaluation Count:729602
yes
Evaluation Count:197278
197278-729602
37 if (*(current - skip) != puc[pl_minus_one-skip])
evaluated: *(current - skip) != puc[pl_minus_one-skip]
TRUEFALSE
yes
Evaluation Count:17128
yes
Evaluation Count:713188
17128-713188
38 break;
executed: break;
Execution Count:17128
17128
39 skip++; -
40 }
executed: }
Execution Count:713561
713561
41 if (skip > pl_minus_one)
evaluated: skip > pl_minus_one
TRUEFALSE
yes
Evaluation Count:197620
yes
Evaluation Count:17128
17128-197620
42 return (current - uc) - pl_minus_one;
executed: return (current - uc) - pl_minus_one;
Execution Count:197948
197948
43 -
44 -
45 -
46 if (skiptable[*(current - skip) & 0xff] == pl)
evaluated: skiptable[*(current - skip) & 0xff] == pl
TRUEFALSE
yes
Evaluation Count:1992
yes
Evaluation Count:15136
1992-15136
47 skip = pl - skip;
executed: skip = pl - skip;
Execution Count:1992
1992
48 else -
49 skip = 1;
executed: skip = 1;
Execution Count:15136
15136
50 } -
51 if (current > end - skip)
evaluated: current > end - skip
TRUEFALSE
yes
Evaluation Count:106478
yes
Evaluation Count:34729654
106478-34729654
52 break;
executed: break;
Execution Count:106478
106478
53 current += skip; -
54 }
executed: }
Execution Count:34336529
34336529
55 } else {
executed: }
Execution Count:162980
162980
56 while (current < end) {
evaluated: current < end
TRUEFALSE
yes
Evaluation Count:1586
yes
Evaluation Count:648
648-1586
57 uint skip = skiptable[foldCase(current, uc) & 0xff]; -
58 if (!skip) {
evaluated: !skip
TRUEFALSE
yes
Evaluation Count:273
yes
Evaluation Count:1313
273-1313
59 -
60 while (skip < pl) {
evaluated: skip < pl
TRUEFALSE
yes
Evaluation Count:9836
yes
Evaluation Count:209
209-9836
61 if (foldCase(current - skip, uc) != foldCase(puc + pl_minus_one - skip, puc))
evaluated: foldCase(current - skip, uc) != foldCase(puc + pl_minus_one - skip, puc)
TRUEFALSE
yes
Evaluation Count:64
yes
Evaluation Count:9772
64-9772
62 break;
executed: break;
Execution Count:64
64
63 skip++; -
64 }
executed: }
Execution Count:9772
9772
65 if (skip > pl_minus_one)
evaluated: skip > pl_minus_one
TRUEFALSE
yes
Evaluation Count:209
yes
Evaluation Count:64
64-209
66 return (current - uc) - pl_minus_one;
executed: return (current - uc) - pl_minus_one;
Execution Count:209
209
67 -
68 -
69 if (skiptable[foldCase(current - skip, uc) & 0xff] == pl)
evaluated: skiptable[foldCase(current - skip, uc) & 0xff] == pl
TRUEFALSE
yes
Evaluation Count:33
yes
Evaluation Count:31
31-33
70 skip = pl - skip;
executed: skip = pl - skip;
Execution Count:33
33
71 else -
72 skip = 1;
executed: skip = 1;
Execution Count:31
31
73 } -
74 if (current > end - skip)
evaluated: current > end - skip
TRUEFALSE
yes
Evaluation Count:739
yes
Evaluation Count:638
638-739
75 break;
executed: break;
Execution Count:739
739
76 current += skip; -
77 }
executed: }
Execution Count:638
638
78 }
executed: }
Execution Count:1387
1387
79 return -1;
executed: return -1;
Execution Count:164367
164367
80} -
81QStringMatcher::QStringMatcher() -
82 : d_ptr(0), q_cs(Qt::CaseSensitive) -
83{ -
84 memset(q_data, 0, sizeof(q_data)); -
85}
executed: }
Execution Count:14
14
86 -
87 -
88 -
89 -
90 -
91 -
92 -
93QStringMatcher::QStringMatcher(const QString &pattern, Qt::CaseSensitivity cs) -
94 : d_ptr(0), q_pattern(pattern), q_cs(cs) -
95{ -
96 p.uc = pattern.unicode(); -
97 p.len = pattern.size(); -
98 bm_init_skiptable((const ushort *)p.uc, p.len, p.q_skiptable, cs); -
99}
executed: }
Execution Count:205
205
100QStringMatcher::QStringMatcher(const QChar *uc, int len, Qt::CaseSensitivity cs) -
101 : d_ptr(0), q_cs(cs) -
102{ -
103 p.uc = uc; -
104 p.len = len; -
105 bm_init_skiptable((const ushort *)p.uc, len, p.q_skiptable, cs); -
106}
executed: }
Execution Count:361842
361842
107 -
108 -
109 -
110 -
111QStringMatcher::QStringMatcher(const QStringMatcher &other) -
112 : d_ptr(0) -
113{ -
114 operator=(other); -
115}
executed: }
Execution Count:1
1
116 -
117 -
118 -
119 -
120QStringMatcher::~QStringMatcher() -
121{ -
122} -
123 -
124 -
125 -
126 -
127QStringMatcher &QStringMatcher::operator=(const QStringMatcher &other) -
128{ -
129 if (this != &other) {
partially evaluated: this != &other
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
130 q_pattern = other.q_pattern; -
131 q_cs = other.q_cs; -
132 memcpy(q_data, other.q_data, sizeof(q_data)); -
133 }
executed: }
Execution Count:1
1
134 return *this;
executed: return *this;
Execution Count:1
1
135} -
136 -
137 -
138 -
139 -
140 -
141 -
142 -
143void QStringMatcher::setPattern(const QString &pattern) -
144{ -
145 q_pattern = pattern; -
146 p.uc = pattern.unicode(); -
147 p.len = pattern.size(); -
148 bm_init_skiptable((const ushort *)pattern.unicode(), pattern.size(), p.q_skiptable, q_cs); -
149}
executed: }
Execution Count:12
12
150QString QStringMatcher::pattern() const -
151{ -
152 if (!q_pattern.isEmpty())
evaluated: !q_pattern.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
153 return q_pattern;
executed: return q_pattern;
Execution Count:1
1
154 return QString(p.uc, p.len);
executed: return QString(p.uc, p.len);
Execution Count:1
1
155} -
156 -
157 -
158 -
159 -
160 -
161 -
162 -
163void QStringMatcher::setCaseSensitivity(Qt::CaseSensitivity cs) -
164{ -
165 if (cs == q_cs)
evaluated: cs == q_cs
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
166 return;
executed: return;
Execution Count:3
3
167 bm_init_skiptable((const ushort *)q_pattern.unicode(), q_pattern.size(), p.q_skiptable, cs); -
168 q_cs = cs; -
169}
executed: }
Execution Count:2
2
170int QStringMatcher::indexIn(const QString &str, int from) const -
171{ -
172 if (from < 0)
evaluated: from < 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:166263
1-166263
173 from = 0;
executed: from = 0;
Execution Count:1
1
174 return bm_find((const ushort *)str.unicode(), str.size(), from, 166264
175 (const ushort *)p.uc, p.len, 166264
176 p.q_skiptable, q_cs);
executed: return bm_find((const ushort *)str.unicode(), str.size(), from, (const ushort *)p.uc, p.len, p.q_skiptable, q_cs);
Execution Count:166264
166264
177} -
178int QStringMatcher::indexIn(const QChar *str, int length, int from) const -
179{ -
180 if (from < 0)
partially evaluated: from < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:199846
0-199846
181 from = 0;
never executed: from = 0;
0
182 return bm_find((const ushort *)str, length, from, 199947
183 (const ushort *)p.uc, p.len, 199947
184 p.q_skiptable, q_cs);
executed: return bm_find((const ushort *)str, length, from, (const ushort *)p.uc, p.len, p.q_skiptable, q_cs);
Execution Count:199947
199947
185} -
186int qFindStringBoyerMoore( -
187 const QChar *haystack, int haystackLen, int haystackOffset, -
188 const QChar *needle, int needleLen, Qt::CaseSensitivity cs) -
189{ -
190 uchar skiptable[256]; -
191 bm_init_skiptable((const ushort *)needle, needleLen, skiptable, cs); -
192 if (haystackOffset < 0)
partially evaluated: haystackOffset < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:215
0-215
193 haystackOffset = 0;
never executed: haystackOffset = 0;
0
194 return bm_find((const ushort *)haystack, haystackLen, haystackOffset, 215
195 (const ushort *)needle, needleLen, skiptable, cs);
executed: return bm_find((const ushort *)haystack, haystackLen, haystackOffset, (const ushort *)needle, needleLen, skiptable, cs);
Execution Count:215
215
196} -
197 -
198 -
199 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial