Skip to content

Commit 226d19a

Browse files
committed
msDrawMap(): optimize pre-processing of WMS/WFS layers
Currently we use msLayerIsVisible() to determine how many potential WMS/WFS layers there are. But this is a costly operation. Rather test the connectiontype, and defer testing msLayerIsVisible() as late as possible.
1 parent 35b82b9 commit 226d19a

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

mapdraw.c

+22-10
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ imageObj *msDrawMap(mapObj *map, int querymap)
220220
#if defined(USE_WMS_LYR) || defined(USE_WFS_LYR)
221221
enum MS_CONNECTION_TYPE lastconnectiontype;
222222
httpRequestObj *pasOWSReqInfo=NULL;
223-
int numOWSLayers=0, numOWSRequests=0;
223+
int numOWSLayers=0;
224+
int numOWSRequests=0;
224225
wmsParamsObj sLastWMSParams;
225226
#endif
226227

@@ -256,30 +257,43 @@ imageObj *msDrawMap(mapObj *map, int querymap)
256257
*/
257258
numOWSLayers=0;
258259
for(i=0; i<map->numlayers; i++) {
259-
if(map->layerorder[i] != -1 &&
260-
msLayerIsVisible(map, GET_LAYER(map,map->layerorder[i])))
260+
if(map->layerorder[i] == -1 )
261+
continue;
262+
263+
lp = GET_LAYER(map,map->layerorder[i]);
264+
if( lp->connectiontype != MS_WMS &&
265+
lp->connectiontype != MS_WFS ) {
266+
continue;
267+
}
261268
numOWSLayers++;
262269
}
263270

264-
265271
if (numOWSLayers > 0) {
272+
266273
/* Alloc and init pasOWSReqInfo...
267274
*/
268-
pasOWSReqInfo = (httpRequestObj *)malloc((numOWSLayers+1)*sizeof(httpRequestObj));
275+
pasOWSReqInfo = (httpRequestObj *)malloc(numOWSLayers*sizeof(httpRequestObj));
269276
if (pasOWSReqInfo == NULL) {
270277
msSetError(MS_MEMERR, "Allocation of httpRequestObj failed.", "msDrawMap()");
271278
return NULL;
272279
}
273-
msHTTPInitRequestObj(pasOWSReqInfo, numOWSLayers+1);
280+
msHTTPInitRequestObj(pasOWSReqInfo, numOWSLayers);
274281
msInitWmsParamsObj(&sLastWMSParams);
275282

276283
/* Pre-download all WMS/WFS layers in parallel before starting to draw map */
277284
lastconnectiontype = MS_SHAPEFILE;
278-
for(i=0; numOWSLayers && i<map->numlayers; i++) {
279-
if(map->layerorder[i] == -1 || !msLayerIsVisible(map, GET_LAYER(map,map->layerorder[i])))
285+
for(i=0; i<map->numlayers; i++) {
286+
if(map->layerorder[i] == -1 )
280287
continue;
281288

282289
lp = GET_LAYER(map,map->layerorder[i]);
290+
if( lp->connectiontype != MS_WMS &&
291+
lp->connectiontype != MS_WFS ) {
292+
continue;
293+
}
294+
295+
if( !msLayerIsVisible(map, lp) )
296+
continue;
283297

284298
#ifdef USE_WMS_LYR
285299
if(lp->connectiontype == MS_WMS) {
@@ -306,9 +320,7 @@ imageObj *msDrawMap(mapObj *map, int querymap)
306320
lastconnectiontype = lp->connectiontype;
307321
}
308322

309-
#ifdef USE_WMS_LYR
310323
msFreeWmsParamsObj(&sLastWMSParams);
311-
#endif
312324
} /* if numOWSLayers > 0 */
313325

314326
if(numOWSRequests && msOWSExecuteRequests(pasOWSReqInfo, numOWSRequests, map, MS_TRUE) == MS_FAILURE) {

maphttp.c

-5
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ void msHTTPCleanup()
113113
* Should be called on a new array of httpRequestObj to initialize them
114114
* for use with msHTTPExecuteRequest(), etc.
115115
*
116-
* Note that users of this module should always allocate and init one
117-
* more instance of httpRequestObj in their array than what they plan to
118-
* use because the terminate_handler() needs the last entry in the array
119-
* to have reqObj->request == NULL
120-
*
121116
**********************************************************************/
122117
void msHTTPInitRequestObj(httpRequestObj *pasReqInfo, int numRequests)
123118
{

0 commit comments

Comments
 (0)