Browse Source

Use 2^n-1 in GSring pre-allocations (so glib doesn't alloc 2^(n+1) for 2^n)

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent
commit
6a56aba0c3
  1. 4
      src/modules/mod_accesslog.c
  2. 2
      src/modules/mod_cache_disk_etag.c
  3. 4
      src/modules/mod_dirlist.c
  4. 4
      src/modules/mod_fortune.c
  5. 4
      src/modules/mod_status.c
  6. 2
      src/response.c
  7. 4
      src/stat_cache.c

4
src/modules/mod_accesslog.c

@ -219,13 +219,13 @@ static GArray *al_parse_format(server *srv, GString *formatstr) {
}
static GString *al_format_log(connection *con, al_data *ald, GArray *format) {
GString *str = g_string_sized_new(256);
GString *str = g_string_sized_new(255);
vrequest *vr = con->mainvr;
response *resp = &vr->response;
request *req = &vr->request;
physical *phys = &vr->physical;
gchar *tmp_str = NULL;
GString *tmp_gstr = g_string_sized_new(128);
GString *tmp_gstr = g_string_sized_new(127);
GString *tmp_gstr2;
guint len = 0;

2
src/modules/mod_cache_disk_etag.c

@ -206,7 +206,7 @@ static handler_t cache_etag_filter_miss(vrequest *vr, filter *f) {
}
static GString* createFileName(vrequest *vr, GString *path, http_header *etagheader) {
GString *file = g_string_sized_new(256);
GString *file = g_string_sized_new(255);
gchar* etag_base64 = g_base64_encode(
etagheader->data->str + (etagheader->keylen + 2),
etagheader->data->len - (etagheader->keylen + 2));

4
src/modules/mod_dirlist.c

@ -262,7 +262,7 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) {
}
/* temporary string for encoded names */
encoded = g_string_sized_new(64);
encoded = g_string_sized_new(64-1);
/* seperate directories from other files */
directories = g_array_sized_new(FALSE, FALSE, sizeof(guint), 16);
@ -308,7 +308,7 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) {
}
listing = g_string_sized_new(4*1024);
listing = g_string_sized_new(4*1024-1);
g_string_append_printf(listing, html_header, vr->request.uri.path->str);
if (dd->css) {

4
src/modules/mod_fortune.c

@ -109,12 +109,12 @@ static gboolean fortune_load(server *srv, plugin* p, value *val) {
/* split lines */
{
GString *line = g_string_sized_new(128);
GString *line = g_string_sized_new(127);
gchar *cur;
for (cur = data; *cur; cur++) {
if (*cur == '\n' && line->len) {
g_array_append_val(fd->cookies, line);
line = g_string_sized_new(128);
line = g_string_sized_new(127);
count++;
}

4
src/modules/mod_status.c

@ -280,7 +280,7 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result
if (!uptime)
uptime = 1;
html = g_string_sized_new(8 * 1024);
html = g_string_sized_new(8 * 1024 - 1);
count_req = g_string_sized_new(10);
count_bin = g_string_sized_new(10);
count_bout = g_string_sized_new(10);
@ -465,7 +465,7 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result
GString *req_len, *resp_len;
guint len;
ts = g_string_sized_new(16);
ts = g_string_sized_new(15);
bytes_in = g_string_sized_new(10);
bytes_out = g_string_sized_new(10);
bytes_in_5s = g_string_sized_new(10);

2
src/response.c

@ -31,7 +31,7 @@ void response_send_headers(connection *con) {
return;
}
head = g_string_sized_new(8*1024);
head = g_string_sized_new(8*1024-1);
if (0 == con->out->length && con->mainvr->handle_response_body == NULL
&& vr->response.http_status >= 400 && vr->response.http_status < 600) {

4
src/stat_cache.c

@ -186,7 +186,7 @@ static gpointer stat_cache_thread(gpointer data) {
assert(size != (gsize)-1);
entry = g_slice_alloc(size);
str = g_string_sized_new(sce->data.path->len + 32);
str = g_string_sized_new(sce->data.path->len + 64);
g_string_append_len(str, GSTR_LEN(sce->data.path));
while ((error = readdir_r(dirp, entry, &result)) == 0 && result != NULL) {
@ -196,7 +196,7 @@ static gpointer stat_cache_thread(gpointer data) {
continue;
}
sced.path = g_string_sized_new(32);
sced.path = g_string_sized_new(63);
g_string_assign(sced.path, result->d_name);
g_string_truncate(str, sce->data.path->len);

Loading…
Cancel
Save