Commit f5d9bcf7 authored by Olly Betts's avatar Olly Betts
Browse files

Use more sensible initial input buffer size

Snowball programs are typically a few KB in size (with the current
largest we ship being the Arabic stemmer at 17.1KB) so starting with
a 10 byte input buffer and increasing its size by 50% plus 40 bytes
each time it fills is inefficient - it needs up to 14 reallocations to
load the sources for the stemmers we ship.

Instead start at 8192 bytes and double the size each time we fill it.
parent 06bac0b6
......@@ -12,7 +12,6 @@ typedef unsigned short symbol;
#define NEW(type, p) struct type * p = (struct type *) MALLOC(sizeof(struct type))
#define NEWVEC(type, p, n) struct type * p = (struct type *) MALLOC(sizeof(struct type) * (n))
#define STARTSIZE 10
#define SIZE(p) ((int *)(p))[-1]
#define CAPACITY(p) ((int *)(p))[-2]
......
......@@ -16,6 +16,8 @@ struct system_word {
#include "syswords.h"
#define INITIAL_INPUT_BUFFER_SIZE 8192
static int hex_to_num(int ch);
static int smaller(int a, int b) { return a < b ? a : b; }
......@@ -24,12 +26,12 @@ extern symbol * get_input(const char * filename) {
FILE * input = fopen(filename, "r");
if (input == 0) { return 0; }
{
symbol * u = create_b(STARTSIZE);
symbol * u = create_b(INITIAL_INPUT_BUFFER_SIZE);
int size = 0;
while (true) {
int ch = getc(input);
if (ch == EOF) break;
if (size >= CAPACITY(u)) u = increase_capacity(u, size/2);
if (size >= CAPACITY(u)) u = increase_capacity(u, size);
u[size++] = ch;
}
fclose(input);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment