Skip to content

Commit

Permalink
General cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggreer committed Sep 7, 2012
1 parent 9c427b4 commit e442c9b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
14 changes: 3 additions & 11 deletions src/main.c
Expand Up @@ -20,9 +20,9 @@ int main(int argc, char **argv) {
int study_opts = 0;
const char *pcre_err = NULL;
int pcre_err_offset = 0;
double time_diff = 0.0;
double time_diff;
pthread_t *workers = NULL;
int workers_len = 0;
int workers_len;

set_log_level(LOG_LEVEL_WARN);

Expand Down Expand Up @@ -68,15 +68,7 @@ int main(int argc, char **argv) {
}
else {
if (opts.word_regexp) {
opts.query_len = opts.query_len + 5; /* "\b" + "\b" + '\0' */
char *word_regexp_query = malloc(opts.query_len);
char *word_sep = "\\b";
strlcpy(word_regexp_query, word_sep, opts.query_len);
strlcat(word_regexp_query, opts.query, opts.query_len);
strlcat(word_regexp_query, word_sep, opts.query_len);
free(opts.query);
opts.query = word_regexp_query;
log_debug("Word regexp query: %s", opts.query);
build_word_regex();
}
opts.re = pcre_compile(opts.query, pcre_opts, &pcre_err, &pcre_err_offset, NULL);
if (opts.re == NULL) {
Expand Down
1 change: 0 additions & 1 deletion src/search.c
Expand Up @@ -83,7 +83,6 @@ void search_buf(const char *buf, const int buf_len,
}
}
else {
/* In my profiling, most of the execution time is spent in this pcre_exec */
while (buf_offset < buf_len &&
(rc = pcre_exec(opts.re, opts.re_extra, buf, buf_len, buf_offset, 0, offset_vector, 3)) >= 0) {
log_debug("Regex match found. File %s, offset %i bytes.", dir_full_path, offset_vector[0]);
Expand Down
11 changes: 11 additions & 0 deletions src/util.c
Expand Up @@ -94,6 +94,17 @@ int invert_matches(match matches[], int matches_len, const int buf_len) {
return (matches_len + 1);
}

void build_word_regex() {
opts.query_len = opts.query_len + 5; /* "\b" + "\b" + '\0' */
char *word_regexp_query = malloc(opts.query_len);
char *word_sep = "\\b";
strlcpy(word_regexp_query, word_sep, opts.query_len);
strlcat(word_regexp_query, opts.query, opts.query_len);
strlcat(word_regexp_query, word_sep, opts.query_len);
free(opts.query);
opts.query = word_regexp_query;
}

/* This function is very hot. It's called on every file. */
int is_binary(const void* buf, const int buf_len) {
int suspicious_bytes = 0;
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Expand Up @@ -40,6 +40,7 @@ char* boyer_moore_strncasestr(const char *s, const char *find, const size_t s_le
strncmp_fp get_strstr(cli_options opts);

int invert_matches(match matches[], int matches_len, const int buf_len);
void build_word_regex();

int is_binary(const void* buf, const int buf_len);
int is_regex(const char* query);
Expand Down

0 comments on commit e442c9b

Please sign in to comment.