From 3861e8289ae40bac168275ce6f10b231e11baa55 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Mon, 28 Nov 2022 22:19:12 +0000 Subject: Refactor string vector code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, string vectors were built by reading input line-by line, and multiple copies of string vectors were made when searching. Now, input is read into one big buffer, and string vectors only contain references to the strings in this buffer. This both speeds up reading of input, and avoids unnecessary copying of strings in various places. The main downside currently is that input read from stdin is no longer UTF-8 normalised. This means, for example, that a search for `e` won't necessarily match `é`. Normalisation is very slow relative to the rest of tofi, however, and not needed for most use-cases. This could either be solved by accepting the slowdown, or making this an option, such as --unicode or --unicode-normalize. --- src/log.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/log.c') diff --git a/src/log.c b/src/log.c index b564a49..e90df3c 100644 --- a/src/log.c +++ b/src/log.c @@ -53,11 +53,11 @@ void log_warning(const char *const fmt, ...) void log_debug(const char *const fmt, ...) { #ifndef DEBUG - return; + //return; #endif static struct timespec start_time; if (start_time.tv_nsec == 0) { - fprintf(stderr, "[ real, cpu, maxRSS]\n"); + fprintf(stderr, "[ real, cpu, maxRSS]\n"); clock_gettime(CLOCK_REALTIME, &start_time); } struct timespec real_time; @@ -73,11 +73,11 @@ void log_debug(const char *const fmt, ...) va_start(args, fmt); fprintf( stderr, - "[%ld.%03ld, %ld.%03ld, %5ld KB][DEBUG]: ", + "[%ld.%06ld, %ld.%06ld, %5ld KB][DEBUG]: ", real_time.tv_sec, - real_time.tv_nsec / 1000000, + real_time.tv_nsec / 1000, cpu_time.tv_sec, - cpu_time.tv_nsec / 1000000, + cpu_time.tv_nsec / 1000, usage.ru_maxrss ); print_indent(stderr); @@ -114,7 +114,7 @@ void log_append_warning(const char *const fmt, ...) void log_append_debug(const char *const fmt, ...) { #ifndef DEBUG - return; + //return; #endif va_list args; va_start(args, fmt); -- cgit v1.2.3