aboutsummaryrefslogtreecommitdiff
path: root/files.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-08-01 15:36:53 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-08-01 15:36:53 -0700
commit0b2de4721f3dcf95d6d0af54c78e197df10f6666 (patch)
tree7b64cefb5c2897510fffdb6c1aa36c792a4c61c4 /files.h
parent8268e67875abeaae99d0793e424514662a84628d (diff)
Moved caching code onto the file, which fixed an issue with file slicing
having stale cache values.
Diffstat (limited to 'files.h')
-rw-r--r--files.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/files.h b/files.h
index 6dc00fa..30179a2 100644
--- a/files.h
+++ b/files.h
@@ -4,13 +4,15 @@
#ifndef FILES__H
#define FILES__H
+#include "types.h"
+
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#define file_err(f, ...) do { fprint_line(stderr, f, __VA_ARGS__); exit(EXIT_FAILURE); } while(false)
-struct pat_s; // declared in types.h
+#define MAX_CACHE_SIZE (1<<14)
typedef struct file_s {
struct file_s *next;
@@ -18,6 +20,10 @@ typedef struct file_s {
char *memory, **lines, *start, *end;
size_t nlines;
struct pat_s *pats;
+ struct {
+ size_t size, occupancy;
+ match_t **matches;
+ } cache;
bool mmapped:1;
} file_t;
@@ -37,6 +43,14 @@ __attribute__((pure, nonnull))
const char *get_line(file_t *f, size_t line_number);
__attribute__((nonnull(1,2,3), format(printf,5,6)))
void fprint_line(FILE *dest, file_t *f, const char *start, const char *end, const char *fmt, ...);
+__attribute__((nonnull(1,3,4,5)))
+bool cache_get(file_t *f, def_t *defs, const char *str, pat_t *pat, match_t **result);
+__attribute__((nonnull(1,3,4)))
+void cache_save(file_t *f, def_t *defs, const char *str, pat_t *pat, match_t *m);
+__attribute__((nonnull))
+void cache_prune(file_t *f, const char *start, const char *end);
+__attribute__((nonnull))
+void cache_destroy(file_t *f);
#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1