diff options
author | Miika Pekkarinen <miipekk@ihme.org> | 2006-10-21 20:37:33 +0000 |
---|---|---|
committer | Miika Pekkarinen <miipekk@ihme.org> | 2006-10-21 20:37:33 +0000 |
commit | a1ac7434534240f9ce88054028a77466c6e61c7c (patch) | |
tree | b2d4fc2f7d8fc0dbea12607ee93df8f2320859a7 /apps/misc.c | |
parent | 593b552486c6502d415f9f31fbaff871a0248cdc (diff) | |
download | rockbox-a1ac7434534240f9ce88054028a77466c6e61c7c.tar.gz rockbox-a1ac7434534240f9ce88054028a77466c6e61c7c.zip |
Implement fast_readline as a function and use it for tagtree also.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11301 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/misc.c')
-rw-r--r-- | apps/misc.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/apps/misc.c b/apps/misc.c index 4be9e43fd9..0936e85569 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -217,6 +217,53 @@ int read_line(int fd, char* buffer, int buffer_size) | |||
217 | return errno ? -1 : num_read; | 217 | return errno ? -1 : num_read; |
218 | } | 218 | } |
219 | 219 | ||
220 | /* Performance optimized version of the previous function. */ | ||
221 | int fast_readline(int fd, char *buf, int buf_size, void *parameters, | ||
222 | int (*callback)(int n, const char *buf, void *parameters)) | ||
223 | { | ||
224 | char *p, *next; | ||
225 | int rc, pos = 0; | ||
226 | int count = 0; | ||
227 | |||
228 | while ( 1 ) | ||
229 | { | ||
230 | next = NULL; | ||
231 | |||
232 | rc = read(fd, &buf[pos], buf_size - pos - 1); | ||
233 | if (rc >= 0) | ||
234 | buf[pos+rc] = '\0'; | ||
235 | |||
236 | if ( (p = strchr(buf, '\r')) != NULL) | ||
237 | { | ||
238 | *p = '\0'; | ||
239 | next = ++p; | ||
240 | } | ||
241 | else | ||
242 | p = buf; | ||
243 | |||
244 | if ( (p = strchr(p, '\n')) != NULL) | ||
245 | { | ||
246 | *p = '\0'; | ||
247 | next = ++p; | ||
248 | } | ||
249 | |||
250 | rc = callback(count, buf, parameters); | ||
251 | if (rc < 0) | ||
252 | return rc; | ||
253 | |||
254 | count++; | ||
255 | if (next) | ||
256 | { | ||
257 | pos = buf_size - ((long)next - (long)buf) - 1; | ||
258 | memmove(buf, next, pos); | ||
259 | } | ||
260 | else | ||
261 | break ; | ||
262 | } | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
220 | #ifdef HAVE_LCD_BITMAP | 267 | #ifdef HAVE_LCD_BITMAP |
221 | 268 | ||
222 | #if LCD_DEPTH == 16 | 269 | #if LCD_DEPTH == 16 |