summaryrefslogtreecommitdiff
path: root/recipes/ipkg/files/1-pkg-parse--Optimize-inefficient-parsing.patch
blob: e7632b11d1de57d271f09a6a18661b4f3eef9ab6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# HG changeset patch
# User pfalcon@localhost
# Date 1178334771 0
# Node ID e4c99830ba0d55813e1774bd6d41039ca640d6a6
# Parent  d324eba24e79a0a86df7978f0511e4632a2732c7
pkg_parse: Optimize inefficient parsing.

Instead of expensively probing all fields in row, dispatch based on the
first letter of the field. Tests show ~12 times reduction in number of calls
to low-level parsing functions.

diff -r d324eba24e79 -r e4c99830ba0d pkg_parse.c
--- a/pkg_parse.c	Fri May 04 23:22:33 2007 +0000
+++ b/pkg_parse.c	Sat May 05 03:12:51 2007 +0000
@@ -241,87 +241,116 @@ int pkg_parse_raw(pkg_t *pkg, char ***ra
 
     for (lines = *raw; *lines; lines++) {
 	/*	fprintf(stderr, "PARSING %s\n", *lines);*/
-	if(isGenericFieldType("Package:", *lines)) 
-	    pkg->name = parseGenericFieldType("Package", *lines);
-	else if(isGenericFieldType("Architecture:", *lines))
-	    pkg->architecture = parseGenericFieldType("Architecture", *lines);
-	else if(isGenericFieldType("Filename:", *lines))
-	    pkg->filename = parseGenericFieldType("Filename", *lines);
-	else if(isGenericFieldType("Section:", *lines))
-	    pkg->section = parseGenericFieldType("Section", *lines);
-	else if(isGenericFieldType("MD5sum:", *lines))
-	    pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
-	/* The old ipkg wrote out status files with the wrong case for MD5sum,
-	   let's parse it either way */
-	else if(isGenericFieldType("MD5Sum:", *lines))
-	    pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
-	else if(isGenericFieldType("Size:", *lines))
-	    pkg->size = parseGenericFieldType("Size", *lines);
-	else if(isGenericFieldType("Source:", *lines))
-	    pkg->source = parseGenericFieldType("Source", *lines);
-	else if(isGenericFieldType("Installed-Size:", *lines))
-	    pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
-	else if(isGenericFieldType("Installed-Time:", *lines)) {
-	     char *time_str = parseGenericFieldType("Installed-Time", *lines);
-	     pkg->installed_time = strtoul(time_str, NULL, 0);
-	} else if(isGenericFieldType("Priority:", *lines))
-	    pkg->priority = parseGenericFieldType("Priority", *lines);
-	else if(isGenericFieldType("Essential:", *lines)) {
-	    char *essential_value;
-	    essential_value = parseGenericFieldType("Essential", *lines);
-	    if (strcmp(essential_value, "yes") == 0) {
-		pkg->essential = 1;
-	    }
-	    free(essential_value);
-	}
-	else if(isGenericFieldType("Status", *lines))
-	    parseStatus(pkg, *lines);
-	else if(isGenericFieldType("Version", *lines))
-	    parseVersion(pkg, *lines);
-	else if(isGenericFieldType("Maintainer", *lines))
-	    pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
-	else if(isGenericFieldType("Conffiles", *lines)){
-	    parseConffiles(pkg, *lines);
-	    reading_conffiles = 1;
-	}
-	else if(isGenericFieldType("Description", *lines)) {
-	    pkg->description = parseGenericFieldType("Description", *lines);
-	    reading_conffiles = 0;
-	    reading_description = 1;
-	}
-
-	else if(isGenericFieldType("Provides", *lines)){
+	switch (**lines) {
+	case 'P':
+	    if(isGenericFieldType("Package:", *lines)) 
+		pkg->name = parseGenericFieldType("Package", *lines);
+	    else if(isGenericFieldType("Priority:", *lines))
+		pkg->priority = parseGenericFieldType("Priority", *lines);
+	    else if(isGenericFieldType("Provides", *lines)){
 /* Here we add the internal_use to align the off by one problem between provides_str and provides */
-            provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
-            if ( alterProvidesLine(*lines,provide) ){
-               return EINVAL;
-            }
-	    pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
+        	provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
+        	if ( alterProvidesLine(*lines,provide) ){
+        	    return EINVAL;
+        	}
+		pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
 /* Let's try to hack a bit here.
    The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
    in alot of other places. We will remove it before writing down the status database */
-            pkg_false_provides=0;
-            free(provide);
-        } 
-
-	else if(isGenericFieldType("Depends", *lines))
-	    pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
-	else if(isGenericFieldType("Pre-Depends", *lines))
-	    pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
-	else if(isGenericFieldType("Recommends", *lines))
-	    pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
-	else if(isGenericFieldType("Suggests", *lines))
-	    pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
-	/* Abhaya: support for conflicts */
-	else if(isGenericFieldType("Conflicts", *lines))
-	    pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
-	else if(isGenericFieldType("Replaces", *lines))
-	    pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
-	else if(line_is_blank(*lines)) {
-	    lines++;
-	    break;
-	}
-	else if(**lines == ' '){
+        	pkg_false_provides=0;
+        	free(provide);
+    	    } 
+	    else if(isGenericFieldType("Pre-Depends", *lines))
+		pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
+	    break;
+
+	case 'A':
+	    if(isGenericFieldType("Architecture:", *lines))
+		pkg->architecture = parseGenericFieldType("Architecture", *lines);
+	    break;
+
+	case 'F':
+	    if(isGenericFieldType("Filename:", *lines))
+		pkg->filename = parseGenericFieldType("Filename", *lines);
+	    break;
+
+	case 'S':
+	    if(isGenericFieldType("Section:", *lines))
+		pkg->section = parseGenericFieldType("Section", *lines);
+	    else if(isGenericFieldType("Size:", *lines))
+		pkg->size = parseGenericFieldType("Size", *lines);
+	    else if(isGenericFieldType("Source:", *lines))
+		pkg->source = parseGenericFieldType("Source", *lines);
+	    else if(isGenericFieldType("Status", *lines))
+		parseStatus(pkg, *lines);
+	    else if(isGenericFieldType("Suggests", *lines))
+		pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
+	    break;
+
+	case 'M':
+	    if(isGenericFieldType("MD5sum:", *lines))
+		pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
+	    /* The old ipkg wrote out status files with the wrong case for MD5sum,
+		let's parse it either way */
+	    else if(isGenericFieldType("MD5Sum:", *lines))
+		pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
+	    else if(isGenericFieldType("Maintainer", *lines))
+		pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
+	    break;
+
+	case 'I':
+	    if(isGenericFieldType("Installed-Size:", *lines))
+		pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
+	    else if(isGenericFieldType("Installed-Time:", *lines)) {
+		char *time_str = parseGenericFieldType("Installed-Time", *lines);
+		pkg->installed_time = strtoul(time_str, NULL, 0);
+	    }	    
+	    break;
+
+	case 'E':
+	    if(isGenericFieldType("Essential:", *lines)) {
+		char *essential_value;
+		essential_value = parseGenericFieldType("Essential", *lines);
+		if (strcmp(essential_value, "yes") == 0) {
+		    pkg->essential = 1;
+		}
+		free(essential_value);
+	    }
+	    break;
+
+	case 'V':
+	    if(isGenericFieldType("Version", *lines))
+		parseVersion(pkg, *lines);
+	    break;
+
+	case 'C':
+	    if(isGenericFieldType("Conffiles", *lines)){
+		parseConffiles(pkg, *lines);
+		reading_conffiles = 1;
+	    }
+	    else if(isGenericFieldType("Conflicts", *lines))
+		pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
+	    break;
+
+	case 'D':
+	    if(isGenericFieldType("Description", *lines)) {
+		pkg->description = parseGenericFieldType("Description", *lines);
+		reading_conffiles = 0;
+		reading_description = 1;
+	    }
+	    else if(isGenericFieldType("Depends", *lines))
+		pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
+	    break;
+
+	case 'R':
+	    if(isGenericFieldType("Recommends", *lines))
+	        pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
+	    else if(isGenericFieldType("Replaces", *lines))
+		pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
+	    
+	    break;
+
+	case ' ':
 	    if(reading_description) {
 		/* we already know it's not blank, so the rest of description */      
 		pkg->description = realloc(pkg->description,
@@ -332,8 +361,18 @@ int pkg_parse_raw(pkg_t *pkg, char ***ra
 	    }
 	    else if(reading_conffiles)
 		parseConffiles(pkg, *lines);
+		
+	    break;
+
+	default:
+	    if(line_is_blank(*lines)) {
+		lines++;
+		goto out;
+	    }
 	}
     }
+out:;
+    
     *raw = lines;
 /* If the ipk has not a Provides line, we insert our false line */ 
     if ( pkg_false_provides==1)