[Mesa-dev] [PATCH 08/12] glcpp: Use strpbrk in the line continuations pass
Gustaw Smolarczyk
wielkiegie at gmail.com
Sat Jan 7 19:53:27 UTC 2017
7 sty 2017 20:04 "Vladislav Egorov" <vegorov180 at gmail.com> napisaĆ(a):
To find newlines the line continuations removal pass uses strchr()
twice -- first time to find '\n', second time to find '\r'. Now,
if the shader uses Unix line separators '\n', the file could contain
no '\r' at all, so each time it will scan to the end of the shader.
Use strpbrk() standard function instead that was specifically created
to search many characters at once.
---
src/compiler/glsl/glcpp/pp.c | 28 ++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/src/compiler/glsl/glcpp/pp.c b/src/compiler/glsl/glcpp/pp.c
index c196868..c4c0196 100644
--- a/src/compiler/glsl/glcpp/pp.c
+++ b/src/compiler/glsl/glcpp/pp.c
@@ -231,7 +231,6 @@ remove_line_continuations(glcpp_parser_t *ctx, const
char *shader)
{
struct string_buffer sb;
const char *backslash, *newline, *search_start;
- const char *cr, *lf;
char newline_separator[3];
int collapsed_newlines = 0;
int separator_len;
@@ -266,23 +265,19 @@ remove_line_continuations(glcpp_parser_t *ctx, const
char *shader)
* examining the first encountered newline terminator, and using the
* same terminator for any newlines we insert.
*/
- cr = strchr(search_start, '\r');
- lf = strchr(search_start, '\n');
+ newline = strpbrk(search_start, "\r\n");
newline_separator[0] = '\n';
newline_separator[1] = '\0';
newline_separator[2] = '\0';
- if (cr == NULL) {
+ if (newline == NULL) {
/* Nothing to do. */
- } else if (lf == NULL) {
- newline_separator[0] = '\r';
- } else if (lf == cr + 1) {
- newline_separator[0] = '\r';
- newline_separator[1] = '\n';
- } else if (cr == lf + 1) {
- newline_separator[0] = '\n';
- newline_separator[1] = '\r';
+ } else if (newline[1] == '\n' || newline[1] == '\r') {
What if we have \n\n ? Won't it match it as a single newline?
Regards,
Gustaw
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170107/bab00075/attachment-0001.html>
More information about the mesa-dev
mailing list