libbb: document plans to speed up line-based input
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 15 Jul 2008 21:29:44 +0000 (21:29 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 15 Jul 2008 21:29:44 +0000 (21:29 -0000)
include/libbb.h
libbb/get_line_from_file.c

index 0db1658f438b96321b1517f4ba941c54535bf9f6..3a7c2eee948be2c8ed666027f1cf2a3de9c5b525 100644 (file)
@@ -618,7 +618,7 @@ extern char *xmalloc_fgets(FILE *file) FAST_FUNC;
 /* Chops off '\n' from the end, unlike fgets: */
 extern char *xmalloc_fgetline(FILE *file) FAST_FUNC;
 /* Same, but doesn't try to conserve space (may have some slack after the end) */
-extern char *xmalloc_fgetline_fast(FILE *file) FAST_FUNC;
+/* extern char *xmalloc_fgetline_fast(FILE *file) FAST_FUNC; */
 
 extern void die_if_ferror(FILE *file, const char *msg) FAST_FUNC;
 extern void die_if_ferror_stdout(void) FAST_FUNC;
@@ -1006,6 +1006,7 @@ typedef struct parser_t {
 } parser_t;
 extern FILE* config_open(parser_t *parser, const char *filename) FAST_FUNC;
 #endif
+/* TODO: add define magic to collapse ntokens/mintokens/comment into one int param */
 extern char* config_read(parser_t *parser, char **tokens, int ntokens, int mintokens, const char *delims, char comment) FAST_FUNC;
 extern void config_close(parser_t *parser) FAST_FUNC;
 
index 7b65ced8d3baa032d4055f6790a9724daba887b4..56761f941959112a02b21547f9e76f768e6a9229 100644 (file)
@@ -68,12 +68,24 @@ char* FAST_FUNC xmalloc_fgetline(FILE *file)
        return c;
 }
 
+#if 0
 /* Faster routines (~twice as fast). +170 bytes. Unused as of 2008-07.
  *
  * NB: they stop at NUL byte too.
  * Performance is important here. Think "grep 50gigabyte_file"...
- * Iironically, grep can't use it because of NUL issue.
+ * Ironically, grep can't use it because of NUL issue.
  * We sorely need C lib to provide fgets which reports size!
+ *
+ * Update:
+ * Actually, uclibc and glibc have it. man getline. It's GNUism,
+ *   but very useful one (if it's as fast as this code).
+ * TODO:
+ * - currently, sed and sort use bb_get_chunk_from_file and heavily
+ *   depend on its "stop on \n or \0" behavior, and STILL they fail
+ *   to handle all cases with embedded NULs correctly. So:
+ * - audit sed and sort; convert them to getline FIRST.
+ * - THEN ditch bb_get_chunk_from_file, replace it with getline.
+ * - provide getline implementation for non-GNU systems.
  */
 
 static char* xmalloc_fgets_internal(FILE *file, int *sizep)
@@ -118,7 +130,6 @@ char* FAST_FUNC xmalloc_fgetline_fast(FILE *file)
        return r; /* not xrealloc(r, sz + 1)! */
 }
 
-#if 0
 char* FAST_FUNC xmalloc_fgets(FILE *file)
 {
        int sz;