summaryrefslogtreecommitdiff
path: root/src/include/common/string.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-09-06 13:57:10 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-09-06 14:13:19 -0400
commit8e3c58e6e459b285d37edb6129e412ed25cd90c1 (patch)
tree853632a3efab6405a36dca91f2e69d5fe399536b /src/include/common/string.h
parent68b603e1a934dcd82e259b7776565ec1776e7a29 (diff)
Refactor pg_get_line() to expose an alternative StringInfo-based API.
Letting the caller provide a StringInfo to read into is helpful when the caller needs to merge lines or otherwise modify the data after it's been read. Notably, now the code added by commit 8f8154a50 can use pg_get_line_append() instead of having its own copy of that logic. A follow-on commit will also make use of this. Also, since StringInfo buffers are a minimum of 1KB long, blindly using pg_get_line() in a loop can eat a lot more memory than one would expect. I discovered for instance that commit e0f05cd5b caused initdb to consume circa 10MB to read postgres.bki, even though that's under 1MB worth of data. A less memory-hungry alternative is to re-use the same StringInfo for all lines and pg_strdup the results. Discussion: https://postgr.es/m/1315832.1599345736@sss.pgh.pa.us
Diffstat (limited to 'src/include/common/string.h')
-rw-r--r--src/include/common/string.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/include/common/string.h b/src/include/common/string.h
index 18aa1dc5aa5..50c241a811b 100644
--- a/src/include/common/string.h
+++ b/src/include/common/string.h
@@ -10,6 +10,8 @@
#ifndef COMMON_STRING_H
#define COMMON_STRING_H
+struct StringInfoData; /* avoid including stringinfo.h here */
+
/* functions in src/common/string.c */
extern bool pg_str_endswith(const char *str, const char *end);
extern int strtoint(const char *pg_restrict str, char **pg_restrict endptr,
@@ -19,6 +21,7 @@ extern int pg_strip_crlf(char *str);
/* functions in src/common/pg_get_line.c */
extern char *pg_get_line(FILE *stream);
+extern bool pg_get_line_append(FILE *stream, struct StringInfoData *buf);
/* functions in src/common/sprompt.c */
extern char *simple_prompt(const char *prompt, bool echo);