6
6
#include "diff.h"
7
7
#include "diffcore.h"
8
8
#include "xdiff-interface.h"
9
+ #include "kwset.h"
9
10
10
11
struct diffgrep_cb {
11
12
regex_t * regexp ;
@@ -146,7 +147,7 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
146
147
147
148
static unsigned int contains (struct diff_filespec * one ,
148
149
const char * needle , unsigned long len ,
149
- regex_t * regexp )
150
+ regex_t * regexp , kwset_t kws )
150
151
{
151
152
unsigned int cnt ;
152
153
unsigned long sz ;
@@ -175,9 +176,12 @@ static unsigned int contains(struct diff_filespec *one,
175
176
176
177
} else { /* Classic exact string match */
177
178
while (sz ) {
178
- const char * found = memmem (data , sz , needle , len );
179
- if (!found )
179
+ size_t offset = kwsexec (kws , data , sz , NULL );
180
+ const char * found ;
181
+ if (offset == -1 )
180
182
break ;
183
+ else
184
+ found = data + offset ;
181
185
sz -= found - data + len ;
182
186
data = found + len ;
183
187
cnt ++ ;
@@ -195,6 +199,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
195
199
unsigned long len = strlen (needle );
196
200
int i , has_changes ;
197
201
regex_t regex , * regexp = NULL ;
202
+ kwset_t kws = NULL ;
198
203
struct diff_queue_struct outq ;
199
204
DIFF_QUEUE_CLEAR (& outq );
200
205
@@ -209,6 +214,10 @@ static void diffcore_pickaxe_count(struct diff_options *o)
209
214
die ("invalid pickaxe regex: %s" , errbuf );
210
215
}
211
216
regexp = & regex ;
217
+ } else {
218
+ kws = kwsalloc (NULL );
219
+ kwsincr (kws , needle , len );
220
+ kwsprep (kws );
212
221
}
213
222
214
223
if (opts & DIFF_PICKAXE_ALL ) {
@@ -219,16 +228,16 @@ static void diffcore_pickaxe_count(struct diff_options *o)
219
228
if (!DIFF_FILE_VALID (p -> two ))
220
229
continue ; /* ignore unmerged */
221
230
/* created */
222
- if (contains (p -> two , needle , len , regexp ))
231
+ if (contains (p -> two , needle , len , regexp , kws ))
223
232
has_changes ++ ;
224
233
}
225
234
else if (!DIFF_FILE_VALID (p -> two )) {
226
- if (contains (p -> one , needle , len , regexp ))
235
+ if (contains (p -> one , needle , len , regexp , kws ))
227
236
has_changes ++ ;
228
237
}
229
238
else if (!diff_unmodified_pair (p ) &&
230
- contains (p -> one , needle , len , regexp ) !=
231
- contains (p -> two , needle , len , regexp ))
239
+ contains (p -> one , needle , len , regexp , kws ) !=
240
+ contains (p -> two , needle , len , regexp , kws ))
232
241
has_changes ++ ;
233
242
}
234
243
if (has_changes )
@@ -251,16 +260,17 @@ static void diffcore_pickaxe_count(struct diff_options *o)
251
260
if (!DIFF_FILE_VALID (p -> two ))
252
261
; /* ignore unmerged */
253
262
/* created */
254
- else if (contains (p -> two , needle , len , regexp ))
263
+ else if (contains (p -> two , needle , len , regexp ,
264
+ kws ))
255
265
has_changes = 1 ;
256
266
}
257
267
else if (!DIFF_FILE_VALID (p -> two )) {
258
- if (contains (p -> one , needle , len , regexp ))
268
+ if (contains (p -> one , needle , len , regexp , kws ))
259
269
has_changes = 1 ;
260
270
}
261
271
else if (!diff_unmodified_pair (p ) &&
262
- contains (p -> one , needle , len , regexp ) !=
263
- contains (p -> two , needle , len , regexp ))
272
+ contains (p -> one , needle , len , regexp , kws ) !=
273
+ contains (p -> two , needle , len , regexp , kws ))
264
274
has_changes = 1 ;
265
275
266
276
if (has_changes )
@@ -271,6 +281,8 @@ static void diffcore_pickaxe_count(struct diff_options *o)
271
281
272
282
if (opts & DIFF_PICKAXE_REGEX )
273
283
regfree (& regex );
284
+ else
285
+ kwsfree (kws );
274
286
275
287
free (q -> queue );
276
288
* q = outq ;
0 commit comments