##// END OF EJS Templates
bdiff: simple splitlines optimization
Christoph Spiel -
r5340:5737845f default
parent child Browse files
Show More
@@ -67,12 +67,13 b' int splitlines(const char *a, int len, s'
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);
@@ -92,7 +93,7 b' int splitlines(const char *a, int len, s'
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;
General Comments 0
You need to be logged in to leave comments. Login now