equal
deleted
inserted
replaced
65 |
65 |
66 int splitlines(const char *a, int len, struct line **lr) |
66 int splitlines(const char *a, int len, struct line **lr) |
67 { |
67 { |
68 int g, h, i; |
68 int g, h, i; |
69 const char *p, *b = a; |
69 const char *p, *b = a; |
|
70 const char * const plast = a + len - 1; |
70 struct line *l; |
71 struct line *l; |
71 |
72 |
72 /* count the lines */ |
73 /* count the lines */ |
73 i = 1; /* extra line for sentinel */ |
74 i = 1; /* extra line for sentinel */ |
74 for (p = a; p < a + len; p++) |
75 for (p = a; p < a + len; p++) |
75 if (*p == '\n' || p == a + len - 1) |
76 if (*p == '\n' || p == plast) |
76 i++; |
77 i++; |
77 |
78 |
78 *lr = l = (struct line *)malloc(sizeof(struct line) * i); |
79 *lr = l = (struct line *)malloc(sizeof(struct line) * i); |
79 if (!l) |
80 if (!l) |
80 return -1; |
81 return -1; |
90 h = *p + rol32(h, 7); |
91 h = *p + rol32(h, 7); |
91 if ((g = h & 0xf0000000)) { |
92 if ((g = h & 0xf0000000)) { |
92 h ^= g >> 24; |
93 h ^= g >> 24; |
93 h ^= g; |
94 h ^= g; |
94 } |
95 } |
95 if (*p == '\n' || p == a + len - 1) { |
96 if (*p == '\n' || p == plast) { |
96 l->len = p - b + 1; |
97 l->len = p - b + 1; |
97 l->h = h * l->len; |
98 l->h = h * l->len; |
98 l->l = b; |
99 l->l = b; |
99 l->n = -1; |
100 l->n = -1; |
100 l++; |
101 l++; |