aboutsummaryrefslogtreecommitdiff
path: root/pattern.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2022-10-26 13:38:38 -0400
committerBruce Hill <bruce@bruce-hill.com>2022-10-26 13:38:38 -0400
commit9e07e08a4888bbc2d479204f6ef2b7cd42c44085 (patch)
treecee28ac5aa6ee44abf699f32fba73d9c584642a4 /pattern.h
parent6b8f1a09d01dbd894988edeb9fb167a3389a4846 (diff)
Microoptimizations
Diffstat (limited to 'pattern.h')
-rw-r--r--pattern.h35
1 files changed, 19 insertions, 16 deletions
diff --git a/pattern.h b/pattern.h
index 7569849..a36885e 100644
--- a/pattern.h
+++ b/pattern.h
@@ -5,6 +5,7 @@
#define PATTERN__H
#include <stdbool.h>
+#include <stdint.h>
#include <sys/types.h>
#define UNBOUNDED(pat) ((pat)->max_matchlen == -1)
@@ -47,27 +48,28 @@ enum pattype_e {
typedef struct pat_s {
struct pat_s *next, **home;
enum pattype_e type;
+ uint32_t id;
const char *start, *end;
// The bounds of the match length (used for backtracking)
- size_t min_matchlen;
- ssize_t max_matchlen; // -1 means unbounded length
+ uint32_t min_matchlen;
+ int32_t max_matchlen; // -1 means unbounded length
union {
const char *string;
struct {
const char *name;
- size_t len;
+ uint32_t len;
} ref;
struct {
const char *name;
- size_t namelen;
+ uint32_t namelen;
struct pat_s *meaning, *next_def;
} def;
struct {
unsigned char low, high;
} range;
struct {
- size_t min;
- ssize_t max;
+ uint32_t min;
+ int32_t max;
struct pat_s *sep, *repeat_pat;
} repetitions;
// TODO: use a linked list instead of a binary tree
@@ -77,29 +79,30 @@ typedef struct pat_s {
struct {
struct pat_s *pat;
const char *text;
- size_t len;
+ uint32_t len;
} replace;
struct {
struct pat_s *capture_pat;
const char *name;
- size_t namelen;
+ uint16_t namelen;
bool backreffable;
} capture;
- struct {
- struct match_s *match;
- const char *at;
- struct pat_s *fallback;
- void *ctx;
- bool visited;
- } leftrec;
+ struct leftrec_info_s *leftrec;
struct {
const char *start, *end, *msg;
} error;
struct pat_s *pat;
} args;
- size_t id;
} pat_t;
+typedef struct leftrec_info_s {
+ struct match_s *match;
+ const char *at;
+ struct pat_s *fallback;
+ void *ctx;
+ bool visited;
+} leftrec_info_t;
+
typedef struct {
bool success;
union {