Skip to content

Commit

Permalink
[read-performance iterate] ring-buffer complete
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Sep 8, 2015
1 parent 1026d35 commit 349e569
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions c/input/peek_file_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include "lib/mlr_globals.h"
#include "input/byte_reader.h"

// This is a ring-buffered peekahead file/string reader.

// Note: Throughout Miller as a general rule I treat struct attributes as if
// there were private attributes. However, for performance, parse_trie_match
// accesses this ring buffer directly.
typedef struct _peek_file_reader_t {
byte_reader_t* pbr;
int peekbuflen;
Expand All @@ -16,11 +21,6 @@ typedef struct _peek_file_reader_t {
int npeeked;
} peek_file_reader_t;

// xxx needing contextual comments here.

// xxx to do: try using a ring buffer (power-of-two length >= buflen) instead
// of the current slipback buffer, for performance

// ----------------------------------------------------------------
static inline peek_file_reader_t* pfr_alloc(byte_reader_t* pbr, int maxnpeek) {
peek_file_reader_t* pfr = mlr_malloc_or_die(sizeof(peek_file_reader_t));
Expand Down Expand Up @@ -67,7 +67,6 @@ static inline char pfr_read_char(peek_file_reader_t* pfr) {
if (pfr->npeeked < 1) {
return pfr->pbr->pread_func(pfr->pbr);
} else {
// xxx to do: make this a ring buffer to avoid the shifts.
char c = pfr->peekbuf[pfr->sob];
pfr->sob = (pfr->sob + 1) & pfr->peekbuflenmask;
pfr->npeeked--;
Expand Down

0 comments on commit 349e569

Please sign in to comment.