Skip to content

Commit 32c6c99

Browse files
committed
Scanner performance improvements
Use flex flags -CF. Pass the to-be-scanned string around as StringInfo type, to avoid querying the length repeatedly. Clean up some code and remove lex-compatibility cruft. Escape backslash sequences inline. Use flex-provided yy_scan_buffer() function to set up input, rather than using myinput().
1 parent ff42814 commit 32c6c99

File tree

8 files changed

+144
-155
lines changed

8 files changed

+144
-155
lines changed

src/backend/parser/Makefile

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Makefile for parser
44
#
5-
# $Header: /cvsroot/pgsql/src/backend/parser/Makefile,v 1.36 2002/03/08 07:12:11 tgl Exp $
5+
# $Header: /cvsroot/pgsql/src/backend/parser/Makefile,v 1.37 2002/04/20 21:56:14 petere Exp $
66
#
77
#-------------------------------------------------------------------------
88

@@ -14,6 +14,8 @@ OBJS= analyze.o gram.o keywords.o parser.o parse_agg.o parse_clause.o \
1414
parse_expr.o parse_func.o parse_node.o parse_oper.o parse_relation.o \
1515
parse_type.o parse_coerce.o parse_target.o scan.o scansup.o
1616

17+
FLEXFLAGS = -CF
18+
1719

1820
all: SUBSYS.o
1921

@@ -42,7 +44,7 @@ endif
4244

4345
$(srcdir)/scan.c: scan.l
4446
ifdef FLEX
45-
$(FLEX) $(FLEXFLAGS) -Pbase_yy -o'$@' $<
47+
$(FLEX) $(FLEXFLAGS) -o'$@' $<
4648
else
4749
@$(missing) flex $< $@
4850
endif
@@ -59,13 +61,3 @@ clean:
5961
rm -f SUBSYS.o $(OBJS)
6062
# And the garbage that might have been left behind by partial build:
6163
@rm -f y.tab.c y.tab.h lex.yy.c
62-
63-
64-
# This is unusual: We actually have to build some of the parts before
65-
# we know what the header file dependencies are.
66-
dep depend: gram.c scan.c
67-
$(CC) -MM $(CFLAGS) *.c >depend
68-
69-
ifeq (depend,$(wildcard depend))
70-
include depend
71-
endif

src/backend/parser/parse_type.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.39 2002/03/30 01:02:41 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.40 2002/04/20 21:56:14 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -473,17 +473,17 @@ typeidTypeRelid(Oid type_id)
473473
void
474474
parseTypeString(const char *str, Oid *type_id, int32 *typmod)
475475
{
476-
char *buf;
476+
StringInfoData buf;
477477
List *raw_parsetree_list;
478478
SelectStmt *stmt;
479479
ResTarget *restarget;
480480
A_Const *aconst;
481481
TypeName *typename;
482482

483-
buf = (char *) palloc(strlen(str) + 16);
484-
sprintf(buf, "SELECT (NULL::%s)", str);
483+
initStringInfo(&buf);
484+
appendStringInfo(&buf, "SELECT (NULL::%s)", str);
485485

486-
raw_parsetree_list = parser(buf, NULL, 0);
486+
raw_parsetree_list = parser(&buf, NULL, 0);
487487

488488
/*
489489
* Make sure we got back exactly what we expected and no more;
@@ -528,5 +528,5 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod)
528528
*type_id = typenameTypeId(typename);
529529
*typmod = typename->typmod;
530530

531-
pfree(buf);
531+
pfree(buf.data);
532532
}

src/backend/parser/parser.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.51 2001/11/05 17:46:26 momjian Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.52 2002/04/20 21:56:14 petere Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -28,12 +28,6 @@
2828
#include "parser/parse_expr.h"
2929

3030

31-
#if defined(FLEX_SCANNER)
32-
extern void DeleteBuffer(void);
33-
#endif /* FLEX_SCANNER */
34-
35-
char *parseString; /* the char* which holds the string to be
36-
* parsed */
3731
List *parsetree; /* result of parsing is left here */
3832

3933
static int lookahead_token; /* one-token lookahead */
@@ -48,24 +42,20 @@ static bool have_lookahead; /* lookahead_token set? */
4842
* Returns a list of raw (un-analyzed) parse trees.
4943
*/
5044
List *
51-
parser(char *str, Oid *typev, int nargs)
45+
parser(StringInfo str, Oid *typev, int nargs)
5246
{
5347
int yyresult;
5448

55-
parseString = str;
5649
parsetree = NIL; /* in case parser forgets to set it */
5750
have_lookahead = false;
5851

59-
scanner_init();
52+
scanner_init(str);
6053
parser_init(typev, nargs);
6154
parse_expr_init();
6255

6356
yyresult = yyparse();
6457

65-
#if defined(FLEX_SCANNER)
66-
DeleteBuffer();
67-
#endif /* FLEX_SCANNER */
68-
58+
scanner_finish();
6959
clearerr(stdin);
7060

7161
if (yyresult) /* error */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy