Remove goog.array.extend

This commit is contained in:
Nicholas L
2016-01-17 15:45:57 +13:00
parent 1089934486
commit d1b6a17773
15 changed files with 53 additions and 39 deletions

View File

@@ -142,3 +142,19 @@ ol.array.flatten = function(arr) {
}, []); }, []);
return data; return data;
}; };
// TODO: Optimisation by storing length or iterating backwards etc
/**
* @param {Array<VALUE>} arr The array to modify.
* @param {Array<VALUE>|VALUE} data The elements or arrays of elements
* to add to arr1.
* @template VALUE
*/
ol.array.extend = function(arr, data) {
var i;
var extension = goog.isArrayLike(data) ? data : [data];
for (i = 0; i < extension.length; i++) {
arr[arr.length] = extension[i];
}
}

View File

@@ -1,11 +1,11 @@
goog.provide('ol.format.GML'); goog.provide('ol.format.GML');
goog.provide('ol.format.GML3'); goog.provide('ol.format.GML3');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.dom.NodeType'); goog.require('goog.dom.NodeType');
goog.require('goog.object'); goog.require('goog.object');
goog.require('ol'); goog.require('ol');
goog.require('ol.array');
goog.require('ol.Feature'); goog.require('ol.Feature');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.format.Feature'); goog.require('ol.format.Feature');
@@ -305,7 +305,7 @@ ol.format.GML3.prototype.readSurface_ = function(node, objectStack) {
var ends = [flatCoordinates.length]; var ends = [flatCoordinates.length];
var i, ii; var i, ii;
for (i = 1, ii = flatLinearRings.length; i < ii; ++i) { for (i = 1, ii = flatLinearRings.length; i < ii; ++i) {
goog.array.extend(flatCoordinates, flatLinearRings[i]); ol.array.extend(flatCoordinates, flatLinearRings[i]);
ends.push(flatCoordinates.length); ends.push(flatCoordinates.length);
} }
polygon.setFlatCoordinates( polygon.setFlatCoordinates(

View File

@@ -3,11 +3,11 @@
// envelopes/extents, only geometries! // envelopes/extents, only geometries!
goog.provide('ol.format.GMLBase'); goog.provide('ol.format.GMLBase');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.dom.NodeType'); goog.require('goog.dom.NodeType');
goog.require('goog.object'); goog.require('goog.object');
goog.require('goog.string'); goog.require('goog.string');
goog.require('ol.array');
goog.require('ol.Feature'); goog.require('ol.Feature');
goog.require('ol.format.Feature'); goog.require('ol.format.Feature');
goog.require('ol.format.XMLFeature'); goog.require('ol.format.XMLFeature');
@@ -451,7 +451,7 @@ ol.format.GMLBase.prototype.readPolygon = function(node, objectStack) {
var ends = [flatCoordinates.length]; var ends = [flatCoordinates.length];
var i, ii; var i, ii;
for (i = 1, ii = flatLinearRings.length; i < ii; ++i) { for (i = 1, ii = flatLinearRings.length; i < ii; ++i) {
goog.array.extend(flatCoordinates, flatLinearRings[i]); ol.array.extend(flatCoordinates, flatLinearRings[i]);
ends.push(flatCoordinates.length); ends.push(flatCoordinates.length);
} }
polygon.setFlatCoordinates( polygon.setFlatCoordinates(

View File

@@ -7,7 +7,6 @@
goog.provide('ol.format.KML'); goog.provide('ol.format.KML');
goog.require('goog.Uri'); goog.require('goog.Uri');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.dom.NodeType'); goog.require('goog.dom.NodeType');
goog.require('goog.object'); goog.require('goog.object');
@@ -1021,7 +1020,7 @@ ol.format.KML.readMultiGeometry_ = function(node, objectStack) {
'geometry should be an ol.geom.Point'); 'geometry should be an ol.geom.Point');
goog.asserts.assert(geometry.getLayout() == layout, goog.asserts.assert(geometry.getLayout() == layout,
'geometry layout should be consistent'); 'geometry layout should be consistent');
goog.array.extend(flatCoordinates, geometry.getFlatCoordinates()); ol.array.extend(flatCoordinates, geometry.getFlatCoordinates());
} }
var multiPoint = new ol.geom.MultiPoint(null); var multiPoint = new ol.geom.MultiPoint(null);
multiPoint.setFlatCoordinates(layout, flatCoordinates); multiPoint.setFlatCoordinates(layout, flatCoordinates);
@@ -1100,7 +1099,7 @@ ol.format.KML.readPolygon_ = function(node, objectStack) {
var ends = [flatCoordinates.length]; var ends = [flatCoordinates.length];
var i, ii; var i, ii;
for (i = 1, ii = flatLinearRings.length; i < ii; ++i) { for (i = 1, ii = flatLinearRings.length; i < ii; ++i) {
goog.array.extend(flatCoordinates, flatLinearRings[i]); ol.array.extend(flatCoordinates, flatLinearRings[i]);
ends.push(flatCoordinates.length); ends.push(flatCoordinates.length);
} }
polygon.setFlatCoordinates( polygon.setFlatCoordinates(
@@ -1955,7 +1954,7 @@ ol.format.KML.prototype.readFeaturesFromNode = function(node, opt_options) {
for (n = node.firstElementChild; n; n = n.nextElementSibling) { for (n = node.firstElementChild; n; n = n.nextElementSibling) {
var fs = this.readFeaturesFromNode(n, opt_options); var fs = this.readFeaturesFromNode(n, opt_options);
if (fs) { if (fs) {
goog.array.extend(features, fs); ol.array.extend(features, fs);
} }
} }
return features; return features;
@@ -2044,14 +2043,14 @@ ol.format.KML.prototype.readNameFromNode = function(node) {
ol.format.KML.prototype.readNetworkLinks = function(source) { ol.format.KML.prototype.readNetworkLinks = function(source) {
var networkLinks = []; var networkLinks = [];
if (ol.xml.isDocument(source)) { if (ol.xml.isDocument(source)) {
goog.array.extend(networkLinks, this.readNetworkLinksFromDocument( ol.array.extend(networkLinks, this.readNetworkLinksFromDocument(
/** @type {Document} */ (source))); /** @type {Document} */ (source)));
} else if (ol.xml.isNode(source)) { } else if (ol.xml.isNode(source)) {
goog.array.extend(networkLinks, this.readNetworkLinksFromNode( ol.array.extend(networkLinks, this.readNetworkLinksFromNode(
/** @type {Node} */ (source))); /** @type {Node} */ (source)));
} else if (goog.isString(source)) { } else if (goog.isString(source)) {
var doc = ol.xml.parse(source); var doc = ol.xml.parse(source);
goog.array.extend(networkLinks, this.readNetworkLinksFromDocument(doc)); ol.array.extend(networkLinks, this.readNetworkLinksFromDocument(doc));
} else { } else {
goog.asserts.fail('unknown type for source'); goog.asserts.fail('unknown type for source');
} }
@@ -2067,7 +2066,7 @@ ol.format.KML.prototype.readNetworkLinksFromDocument = function(doc) {
var n, networkLinks = []; var n, networkLinks = [];
for (n = doc.firstChild; n; n = n.nextSibling) { for (n = doc.firstChild; n; n = n.nextSibling) {
if (n.nodeType == goog.dom.NodeType.ELEMENT) { if (n.nodeType == goog.dom.NodeType.ELEMENT) {
goog.array.extend(networkLinks, this.readNetworkLinksFromNode(n)); ol.array.extend(networkLinks, this.readNetworkLinksFromNode(n));
} }
} }
return networkLinks; return networkLinks;
@@ -2094,7 +2093,7 @@ ol.format.KML.prototype.readNetworkLinksFromNode = function(node) {
(localName == 'Document' || (localName == 'Document' ||
localName == 'Folder' || localName == 'Folder' ||
localName == 'kml')) { localName == 'kml')) {
goog.array.extend(networkLinks, this.readNetworkLinksFromNode(n)); ol.array.extend(networkLinks, this.readNetworkLinksFromNode(n));
} }
} }
return networkLinks; return networkLinks;

View File

@@ -1,10 +1,10 @@
// FIXME add typedef for stack state objects // FIXME add typedef for stack state objects
goog.provide('ol.format.OSMXML'); goog.provide('ol.format.OSMXML');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.dom.NodeType'); goog.require('goog.dom.NodeType');
goog.require('goog.object'); goog.require('goog.object');
goog.require('ol.array');
goog.require('ol.Feature'); goog.require('ol.Feature');
goog.require('ol.format.Feature'); goog.require('ol.format.Feature');
goog.require('ol.format.XMLFeature'); goog.require('ol.format.XMLFeature');
@@ -103,7 +103,7 @@ ol.format.OSMXML.readWay_ = function(node, objectStack) {
var flatCoordinates = /** @type {Array.<number>} */ ([]); var flatCoordinates = /** @type {Array.<number>} */ ([]);
for (var i = 0, ii = values.ndrefs.length; i < ii; i++) { for (var i = 0, ii = values.ndrefs.length; i < ii; i++) {
var point = state.nodes[values.ndrefs[i]]; var point = state.nodes[values.ndrefs[i]];
goog.array.extend(flatCoordinates, point); ol.array.extend(flatCoordinates, point);
} }
var geometry; var geometry;
if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) { if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) {

View File

@@ -1,6 +1,5 @@
goog.provide('ol.format.WMSGetFeatureInfo'); goog.provide('ol.format.WMSGetFeatureInfo');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.dom.NodeType'); goog.require('goog.dom.NodeType');
goog.require('goog.object'); goog.require('goog.object');
@@ -118,7 +117,7 @@ ol.format.WMSGetFeatureInfo.prototype.readFeatures_ = function(node, objectStack
var layerFeatures = ol.xml.pushParseAndPop( var layerFeatures = ol.xml.pushParseAndPop(
[], parsersNS, layer, objectStack, this.gmlFormat_); [], parsersNS, layer, objectStack, this.gmlFormat_);
if (layerFeatures) { if (layerFeatures) {
goog.array.extend(features, layerFeatures); ol.array.extend(features, layerFeatures);
} }
} }
} }

View File

@@ -1,9 +1,9 @@
goog.provide('ol.format.XMLFeature'); goog.provide('ol.format.XMLFeature');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.dom.NodeType'); goog.require('goog.dom.NodeType');
goog.require('goog.dom.xml'); goog.require('goog.dom.xml');
goog.require('ol.array');
goog.require('ol.format.Feature'); goog.require('ol.format.Feature');
goog.require('ol.format.FormatType'); goog.require('ol.format.FormatType');
goog.require('ol.proj'); goog.require('ol.proj');
@@ -108,7 +108,7 @@ ol.format.XMLFeature.prototype.readFeaturesFromDocument = function(
var n; var n;
for (n = doc.firstChild; n; n = n.nextSibling) { for (n = doc.firstChild; n; n = n.nextSibling) {
if (n.nodeType == goog.dom.NodeType.ELEMENT) { if (n.nodeType == goog.dom.NodeType.ELEMENT) {
goog.array.extend(features, this.readFeaturesFromNode(n, opt_options)); ol.array.extend(features, this.readFeaturesFromNode(n, opt_options));
} }
} }
return features; return features;

View File

@@ -1,8 +1,8 @@
goog.provide('ol.geom.LineString'); goog.provide('ol.geom.LineString');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('ol'); goog.require('ol');
goog.require('ol.array');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.GeometryLayout');
goog.require('ol.geom.GeometryType'); goog.require('ol.geom.GeometryType');
@@ -72,7 +72,7 @@ ol.geom.LineString.prototype.appendCoordinate = function(coordinate) {
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = coordinate.slice(); this.flatCoordinates = coordinate.slice();
} else { } else {
goog.array.extend(this.flatCoordinates, coordinate); ol.array.extend(this.flatCoordinates, coordinate);
} }
this.changed(); this.changed();
}; };

View File

@@ -1,8 +1,8 @@
goog.provide('ol.geom.MultiLineString'); goog.provide('ol.geom.MultiLineString');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('ol'); goog.require('ol');
goog.require('ol.array');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.GeometryLayout');
goog.require('ol.geom.GeometryType'); goog.require('ol.geom.GeometryType');
@@ -65,7 +65,7 @@ ol.geom.MultiLineString.prototype.appendLineString = function(lineString) {
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = lineString.getFlatCoordinates().slice(); this.flatCoordinates = lineString.getFlatCoordinates().slice();
} else { } else {
goog.array.extend( ol.array.extend(
this.flatCoordinates, lineString.getFlatCoordinates().slice()); this.flatCoordinates, lineString.getFlatCoordinates().slice());
} }
this.ends_.push(this.flatCoordinates.length); this.ends_.push(this.flatCoordinates.length);
@@ -216,7 +216,7 @@ ol.geom.MultiLineString.prototype.getFlatMidpoints = function() {
var end = ends[i]; var end = ends[i];
var midpoint = ol.geom.flat.interpolate.lineString( var midpoint = ol.geom.flat.interpolate.lineString(
flatCoordinates, offset, end, stride, 0.5); flatCoordinates, offset, end, stride, 0.5);
goog.array.extend(midpoints, midpoint); ol.array.extend(midpoints, midpoint);
offset = end; offset = end;
} }
return midpoints; return midpoints;
@@ -319,7 +319,7 @@ ol.geom.MultiLineString.prototype.setLineStrings = function(lineStrings) {
goog.asserts.assert(lineString.getLayout() == layout, goog.asserts.assert(lineString.getLayout() == layout,
'layout of lineString should match layout'); 'layout of lineString should match layout');
} }
goog.array.extend(flatCoordinates, lineString.getFlatCoordinates()); ol.array.extend(flatCoordinates, lineString.getFlatCoordinates());
ends.push(flatCoordinates.length); ends.push(flatCoordinates.length);
} }
this.setFlatCoordinates(layout, flatCoordinates, ends); this.setFlatCoordinates(layout, flatCoordinates, ends);

View File

@@ -1,7 +1,7 @@
goog.provide('ol.geom.MultiPoint'); goog.provide('ol.geom.MultiPoint');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('ol.array');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.GeometryLayout');
goog.require('ol.geom.GeometryType'); goog.require('ol.geom.GeometryType');
@@ -40,7 +40,7 @@ ol.geom.MultiPoint.prototype.appendPoint = function(point) {
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = point.getFlatCoordinates().slice(); this.flatCoordinates = point.getFlatCoordinates().slice();
} else { } else {
goog.array.extend(this.flatCoordinates, point.getFlatCoordinates()); ol.array.extend(this.flatCoordinates, point.getFlatCoordinates());
} }
this.changed(); this.changed();
}; };

View File

@@ -1,9 +1,9 @@
goog.provide('ol.geom.MultiPolygon'); goog.provide('ol.geom.MultiPolygon');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.object'); goog.require('goog.object');
goog.require('ol'); goog.require('ol');
goog.require('ol.array');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.GeometryLayout');
goog.require('ol.geom.GeometryType'); goog.require('ol.geom.GeometryType');
@@ -100,7 +100,7 @@ ol.geom.MultiPolygon.prototype.appendPolygon = function(polygon) {
this.endss_.push(); this.endss_.push();
} else { } else {
var offset = this.flatCoordinates.length; var offset = this.flatCoordinates.length;
goog.array.extend(this.flatCoordinates, polygon.getFlatCoordinates()); ol.array.extend(this.flatCoordinates, polygon.getFlatCoordinates());
ends = polygon.getEnds().slice(); ends = polygon.getEnds().slice();
var i, ii; var i, ii;
for (i = 0, ii = ends.length; i < ii; ++i) { for (i = 0, ii = ends.length; i < ii; ++i) {
@@ -424,7 +424,7 @@ ol.geom.MultiPolygon.prototype.setPolygons = function(polygons) {
for (j = 0, jj = ends.length; j < jj; ++j) { for (j = 0, jj = ends.length; j < jj; ++j) {
ends[j] += offset; ends[j] += offset;
} }
goog.array.extend(flatCoordinates, polygon.getFlatCoordinates()); ol.array.extend(flatCoordinates, polygon.getFlatCoordinates());
endss.push(ends); endss.push(ends);
} }
this.setFlatCoordinates(layout, flatCoordinates, endss); this.setFlatCoordinates(layout, flatCoordinates, endss);

View File

@@ -4,6 +4,7 @@ goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.math'); goog.require('goog.math');
goog.require('ol'); goog.require('ol');
goog.require('ol.array');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.GeometryLayout');
goog.require('ol.geom.GeometryType'); goog.require('ol.geom.GeometryType');
@@ -94,7 +95,7 @@ ol.geom.Polygon.prototype.appendLinearRing = function(linearRing) {
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = linearRing.getFlatCoordinates().slice(); this.flatCoordinates = linearRing.getFlatCoordinates().slice();
} else { } else {
goog.array.extend(this.flatCoordinates, linearRing.getFlatCoordinates()); ol.array.extend(this.flatCoordinates, linearRing.getFlatCoordinates());
} }
this.ends_.push(this.flatCoordinates.length); this.ends_.push(this.flatCoordinates.length);
this.changed(); this.changed();
@@ -390,7 +391,7 @@ ol.geom.Polygon.circular = function(sphere, center, radius, opt_n) {
var flatCoordinates = []; var flatCoordinates = [];
var i; var i;
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
goog.array.extend( ol.array.extend(
flatCoordinates, sphere.offset(center, radius, 2 * Math.PI * i / n)); flatCoordinates, sphere.offset(center, radius, 2 * Math.PI * i / n));
} }
flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]); flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]);

View File

@@ -3,7 +3,6 @@ goog.provide('ol.interaction.SelectEvent');
goog.provide('ol.interaction.SelectEventType'); goog.provide('ol.interaction.SelectEventType');
goog.provide('ol.interaction.SelectFilterFunction'); goog.provide('ol.interaction.SelectFilterFunction');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.events'); goog.require('goog.events');
goog.require('goog.events.Event'); goog.require('goog.events.Event');
@@ -384,9 +383,9 @@ ol.interaction.Select.prototype.setMap = function(map) {
*/ */
ol.interaction.Select.getDefaultStyleFunction = function() { ol.interaction.Select.getDefaultStyleFunction = function() {
var styles = ol.style.createDefaultEditingStyles(); var styles = ol.style.createDefaultEditingStyles();
goog.array.extend(styles[ol.geom.GeometryType.POLYGON], ol.array.extend(styles[ol.geom.GeometryType.POLYGON],
styles[ol.geom.GeometryType.LINE_STRING]); styles[ol.geom.GeometryType.LINE_STRING]);
goog.array.extend(styles[ol.geom.GeometryType.GEOMETRY_COLLECTION], ol.array.extend(styles[ol.geom.GeometryType.GEOMETRY_COLLECTION],
styles[ol.geom.GeometryType.LINE_STRING]); styles[ol.geom.GeometryType.LINE_STRING]);
return function(feature, resolution) { return function(feature, resolution) {

View File

@@ -5,7 +5,6 @@ goog.provide('ol.source.Vector');
goog.provide('ol.source.VectorEvent'); goog.provide('ol.source.VectorEvent');
goog.provide('ol.source.VectorEventType'); goog.provide('ol.source.VectorEventType');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.events'); goog.require('goog.events');
goog.require('goog.events.Event'); goog.require('goog.events.Event');
@@ -19,6 +18,7 @@ goog.require('ol.Feature');
goog.require('ol.FeatureLoader'); goog.require('ol.FeatureLoader');
goog.require('ol.LoadingStrategy'); goog.require('ol.LoadingStrategy');
goog.require('ol.ObjectEventType'); goog.require('ol.ObjectEventType');
goog.require('ol.array');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.featureloader'); goog.require('ol.featureloader');
goog.require('ol.loadingstrategy'); goog.require('ol.loadingstrategy');
@@ -552,7 +552,7 @@ ol.source.Vector.prototype.getFeatures = function() {
} else if (this.featuresRtree_) { } else if (this.featuresRtree_) {
features = this.featuresRtree_.getAll(); features = this.featuresRtree_.getAll();
if (!goog.object.isEmpty(this.nullGeometryFeatures_)) { if (!goog.object.isEmpty(this.nullGeometryFeatures_)) {
goog.array.extend( ol.array.extend(
features, goog.object.getValues(this.nullGeometryFeatures_)); features, goog.object.getValues(this.nullGeometryFeatures_));
} }
} }

View File

@@ -1,11 +1,11 @@
goog.provide('ol.xml'); goog.provide('ol.xml');
goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.dom.NodeType'); goog.require('goog.dom.NodeType');
goog.require('goog.dom.xml'); goog.require('goog.dom.xml');
goog.require('goog.object'); goog.require('goog.object');
goog.require('goog.userAgent'); goog.require('goog.userAgent');
goog.require('ol.array');
/** /**
@@ -370,7 +370,7 @@ ol.xml.makeArrayExtender = function(valueReader, opt_this) {
(objectStack[objectStack.length - 1]); (objectStack[objectStack.length - 1]);
goog.asserts.assert(goog.isArray(array), goog.asserts.assert(goog.isArray(array),
'objectStack is supposed to be an array of arrays'); 'objectStack is supposed to be an array of arrays');
goog.array.extend(array, value); ol.array.extend(array, value);
} }
}); });
}; };