From d45b62491edb475e7eb1e3885ea3c8fb0d4fdd6b Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Tue, 25 May 2021 13:31:05 +1000 Subject: slightly faster code --- bin/conflate.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'bin/conflate.js') diff --git a/bin/conflate.js b/bin/conflate.js index 5467231..96e4e00 100755 --- a/bin/conflate.js +++ b/bin/conflate.js @@ -143,13 +143,25 @@ const conflate = new Transform({ // address found within an existing OSM address polygon feature.properties._osmtype = osmPoly.properties['@type'] feature.properties._osmid = osmPoly.properties['@id'] + outputStreams.withinExistingOSMAddressPoly.write(feature) } else { // address not found within an existing OSM address polygon // see if any address with the same number and street in the same block if (block.id in osmAddrPoints || block.id in osmAddrPolygonsByBlock) { - const osmAddrWithinBlock = [osmAddrPoints[block.id] || [], osmAddrPolygonsByBlock[block.id] || []].flat() + // for loop with push is faster than spread then flat, or concat + const osmAddrWithinBlock = [] + if (block.id in osmAddrPoints) { + for (let i = 0; i < osmAddrPoints[block.id].length; i++) { + osmAddrWithinBlock.push(osmAddrPoints[block.id][i]) + } + } + if (block.id in osmAddrPolygonsByBlock) { + for (let i = 0; i < osmAddrPolygonsByBlock[block.id].length; i++) { + osmAddrWithinBlock.push(osmAddrPolygonsByBlock[block.id][i]) + } + } const matches = osmAddrWithinBlock.filter(osmAddr => { const osmStreet = osmAddr.properties['addr:street'] -- cgit v1.2.3