[dovecot-cvs] dovecot/src/lib-storage/index index-mail-headers.c,
1.42, 1.43 index-mail.c, 1.72, 1.73 index-mail.h, 1.29, 1.30
cras at dovecot.org
cras at dovecot.org
Tue Mar 29 18:56:21 EEST 2005
Update of /var/lib/cvs/dovecot/src/lib-storage/index
In directory talvi:/tmp/cvs-serv26923/lib-storage/index
Modified Files:
index-mail-headers.c index-mail.c index-mail.h
Log Message:
Changed some buffers to arrays.
Index: index-mail-headers.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail-headers.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- index-mail-headers.c 15 Mar 2005 19:01:52 -0000 1.42
+++ index-mail-headers.c 29 Mar 2005 15:56:19 -0000 1.43
@@ -40,30 +40,29 @@
const unsigned char *header, *data;
const uint8_t *match;
buffer_t *buf;
- size_t i, j, size, data_size, match_idx, match_size;
+ size_t data_size;
+ unsigned int i, j, count, match_idx, match_count;
int noncontiguous;
t_push();
- lines = buffer_get_modifyable_data(mail->header_lines, &size);
- size /= sizeof(*lines);
+ lines = array_get_modifyable(&mail->header_lines, &count);
/* sort it first so fields are grouped together and ordered by
line number */
- qsort(lines, size, sizeof(*lines), header_line_cmp);
+ qsort(lines, count, sizeof(*lines), header_line_cmp);
- match = buffer_get_data(mail->header_match, &match_size);
+ match = array_get(&mail->header_match, &match_count);
header = buffer_get_data(mail->header_data, NULL);
buf = buffer_create_dynamic(pool_datastack_create(), 256);
- for (i = match_idx = 0; i < size; i = j) {
+ for (i = match_idx = 0; i < count; i = j) {
while (match_idx < lines[i].field_idx &&
- match_idx < match_size) {
+ match_idx < match_count) {
if (match[match_idx] == mail->header_match_value) {
/* this header doesn't exist. remember that. */
- buffer_write(mail->header_offsets,
- match_idx * sizeof(null),
- &null, sizeof(null));
+ array_idx_set(&mail->header_offsets,
+ match_idx, &null);
mail_cache_add(mail->trans->cache_trans,
mail->data.seq, match_idx,
NULL, 0);
@@ -77,7 +76,7 @@
sizeof(lines[i].line_num));
noncontiguous = FALSE;
- for (j = i+1; j < size; j++) {
+ for (j = i+1; j < count; j++) {
if (lines[j].field_idx != lines[i].field_idx)
break;
@@ -105,7 +104,7 @@
lines[i].field_idx, data, data_size);
}
- for (; match_idx < match_size; match_idx++) {
+ for (; match_idx < match_count; match_idx++) {
if (match[match_idx] == mail->header_match_value) {
/* this header doesn't exist. remember that. */
mail_cache_add(mail->trans->cache_trans,
@@ -126,35 +125,37 @@
mail->header_seq = mail->data.seq;
if (mail->header_data == NULL) {
mail->header_data = buffer_create_dynamic(default_pool, 4096);
- mail->header_lines = buffer_create_dynamic(default_pool, 256);
- mail->header_match = buffer_create_dynamic(default_pool, 64);
- mail->header_offsets = buffer_create_dynamic(default_pool, 256);
+ ARRAY_CREATE(&mail->header_lines, default_pool,
+ struct index_mail_line, 32);
+ ARRAY_CREATE(&mail->header_match, default_pool, uint8_t, 32);
+ ARRAY_CREATE(&mail->header_offsets, default_pool,
+ uint32_t, 32);
} else {
buffer_set_used_size(mail->header_data, 0);
- buffer_set_used_size(mail->header_lines, 0);
- buffer_set_used_size(mail->header_offsets, 0);
+ array_clear(&mail->header_lines);
+ array_clear(&mail->header_offsets);
}
mail->header_match_value += 2;
if (mail->header_match_value == 0) {
- /* wrapped, we'll have to clear the buffer */
- memset(buffer_get_modifyable_data(mail->header_match, NULL), 0,
- buffer_get_size(mail->header_match));
+ /* @UNSAFE: wrapped, we'll have to clear the buffer */
+ memset(array_modifyable_idx(&mail->header_match, 0), 0,
+ array_count(&mail->header_match));
mail->header_match_value = 2;
}
if (headers != NULL) {
for (i = 0; i < headers->count; i++) {
- buffer_write(mail->header_match, headers->idx[i],
- &mail->header_match_value, 1);
+ array_idx_set(&mail->header_match, headers->idx[i],
+ &mail->header_match_value);
}
}
if (mail->wanted_headers != NULL && mail->wanted_headers != headers) {
headers = mail->wanted_headers;
for (i = 0; i < headers->count; i++) {
- buffer_write(mail->header_match, headers->idx[i],
- &mail->header_match_value, 1);
+ array_idx_set(&mail->header_match, headers->idx[i],
+ &mail->header_match_value);
}
}
}
@@ -178,9 +179,8 @@
struct index_mail_data *data = &mail->data;
enum mail_cache_decision_type decision;
const char *cache_field_name;
- unsigned int field_idx;
+ unsigned int field_idx, count;
uint8_t *match;
- size_t size;
int timezone, first_hdr = FALSE;
data->parse_line_num++;
@@ -262,13 +262,13 @@
}
}
- match = buffer_get_modifyable_data(mail->header_match, &size);
- if (field_idx < size && match[field_idx] == mail->header_match_value) {
+ match = array_get_modifyable(&mail->header_match, &count);
+ if (field_idx < count && match[field_idx] == mail->header_match_value) {
/* first header */
first_hdr = TRUE;
match[field_idx]++;
} else if (!data->parse_line.cache &&
- (field_idx >= size ||
+ (field_idx >= count ||
(match[field_idx] & ~1) != mail->header_match_value)) {
/* we don't need to do anything with this header */
return TRUE;
@@ -283,9 +283,7 @@
if (first_hdr) {
/* save the offset to first header */
uint32_t pos = str_len(mail->header_data);
- buffer_write(mail->header_offsets,
- field_idx * sizeof(pos),
- &pos, sizeof(pos));
+ array_idx_set(&mail->header_offsets, field_idx, &pos);
}
}
str_append_n(mail->header_data, hdr->value, hdr->value_len);
@@ -293,8 +291,7 @@
str_append(mail->header_data, "\n");
if (!hdr->continues) {
data->parse_line.end_pos = str_len(mail->header_data);
- buffer_append(mail->header_lines, &data->parse_line,
- sizeof(data->parse_line));
+ array_append(&mail->header_lines, &data->parse_line, 1);
}
return TRUE;
}
@@ -412,10 +409,10 @@
unsigned int field_idx)
{
const uint8_t *match;
- size_t size;
+ unsigned int count;
- match = buffer_get_data(mail->header_match, &size);
- if (field_idx >= size)
+ match = array_get(&mail->header_match, &count);
+ if (field_idx >= count)
return -1;
if (match[field_idx] == mail->header_match_value)
@@ -430,11 +427,11 @@
{
const unsigned char *data;
const uint32_t *offsets;
+ unsigned int count;
size_t size;
- offsets = buffer_get_data(mail->header_offsets, &size);
- i_assert(field_idx * sizeof(*offsets) <= size &&
- offsets[field_idx] != 0);
+ offsets = array_get(&mail->header_offsets, &count);
+ i_assert(field_idx <= count && offsets[field_idx] != 0);
data = buffer_get_data(mail->header_data, &size);
size = get_header_size(mail->header_data, offsets[field_idx]);
Index: index-mail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- index-mail.c 15 Mar 2005 19:01:52 -0000 1.72
+++ index-mail.c 29 Mar 2005 15:56:19 -0000 1.73
@@ -759,12 +759,12 @@
if (mail->header_data != NULL)
buffer_free(mail->header_data);
- if (mail->header_lines != NULL)
- buffer_free(mail->header_lines);
- if (mail->header_match != NULL)
- buffer_free(mail->header_match);
- if (mail->header_offsets != NULL)
- buffer_free(mail->header_offsets);
+ if (array_is_created(&mail->header_lines))
+ array_free(&mail->header_lines);
+ if (array_is_created(&mail->header_match))
+ array_free(&mail->header_match);
+ if (array_is_created(&mail->header_offsets))
+ array_free(&mail->header_offsets);
pool_unref(mail->data_pool);
pool_unref(mail->mail.pool);
Index: index-mail.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- index-mail.h 15 Mar 2005 19:01:52 -0000 1.29
+++ index-mail.h 29 Mar 2005 15:56:19 -0000 1.30
@@ -101,9 +101,9 @@
/* per-mail variables, here for performance reasons: */
uint32_t header_seq;
string_t *header_data;
- buffer_t *header_lines;
- buffer_t *header_match;
- buffer_t *header_offsets;
+ array_t ARRAY_DEFINE(header_lines, struct index_mail_line);
+ array_t ARRAY_DEFINE(header_match, uint8_t);
+ array_t ARRAY_DEFINE(header_offsets, uint32_t);
uint8_t header_match_value;
};
More information about the dovecot-cvs
mailing list