Merge pull request #72 from arlas/patch-7

optimizations from http://developer.android.com/guide/practices/design/pe
This commit is contained in:
pavolzibrita 2011-09-19 21:32:28 -07:00
commit eabcf13509
8 changed files with 50 additions and 44 deletions

View file

@ -133,7 +133,8 @@ public class BinaryInspector {
BinaryIndexPart part = indexes[c].getIndexes().get(i);
if(part instanceof MapIndex){
List<MapRoot> roots = ((MapIndex) part).getRoots();
for(int j=0; j<roots.size(); j++){
int rsize = roots.size();
for(int j=0; j<rsize; j++){
partsSet[c].add((i+1f)+(j+1)/10f);
}
}
@ -184,7 +185,8 @@ public class BinaryInspector {
List<MapRoot> toSkip = new ArrayList<MapRoot>();
int newL = 0;
int tagAndFieldSize = CodedOutputStream.computeTagSize(OsmandOdb.OsmAndMapIndex.LEVELS_FIELD_NUMBER) + 4;
for(int j=0; j<roots.size(); j++){
int rsize = roots.size();
for(int j=0; j<rsize; j++){
if (!partSet.contains(i + 1f + (j+1)*0.1f)) {
newL -= (roots.get(j).getLength() + tagAndFieldSize);
toSkip.add(roots.get(j));

View file

@ -17,13 +17,14 @@ public class MapAlgorithms {
}
ArrayList<Integer> l = new ArrayList<Integer>();
int first = 0;
while(first < n.size()){
int nsize = n.size();
while(first < nsize){
if(n.get(first) != null){
break;
}
first++;
}
int last = n.size() - 1;
int last = nsize - 1;
while (last >= 0) {
if (n.get(last) != null) {
break;
@ -54,7 +55,8 @@ public class MapAlgorithms {
}
simplifyDouglasPeucker(n, zoom, epsilon, l, first, last);
w.addNode(n.get(first));
for (int i = 0; i < l.size(); i++) {
int lsize = l.size();
for (int i = 0; i < lsize; i++) {
w.addNode(n.get(l.get(i)));
}
if (cycle) {
@ -99,7 +101,6 @@ public class MapAlgorithms {
public static boolean isClockwiseWay(Way w){
return isClockwiseWay(Collections.singletonList(w));
}
public static boolean isClockwiseWay(List<Way> ways){
@ -120,12 +121,13 @@ public class MapAlgorithms {
for(Way w : ways){
List<Node> ns = w.getNodes();
int startInd = 0;
if(firstWay && ns.size() > 0){
int nssize = ns.size();
if(firstWay && nssize > 0){
prev = ns.get(0);
startInd = 1;
firstWay = false;
}
for(int i = startInd; i < ns.size();i++) {
for(int i = startInd; i < nssize;i++) {
Node next = ns.get(i);
double rlon = ray_intersect_lon(prev, next, lat, lon);
if(rlon != - 360d){
@ -161,8 +163,6 @@ public class MapAlgorithms {
}
return clockwiseSum >= 0;
}
// try to intersect from left to right
@ -194,8 +194,5 @@ public class MapAlgorithms {
}
}
}
}
}
}

View file

@ -8,7 +8,6 @@ import net.osmand.osm.MapUtils;
import net.osmand.osm.Relation;
import net.osmand.osm.Way;
public class TransportRoute extends MapObject {
private List<Way> ways;
private List<TransportStop> forwardStops = new ArrayList<TransportStop>();
@ -85,14 +84,14 @@ public class TransportRoute extends MapObject {
public int getAvgBothDistance(){
int d = 0;
for(int i=1; i< backwardStops.size(); i++){
int bSsize = backwardStops.size();
int fSsize = forwardStops.size();
for(int i=1; i< bSsize; i++){
d += MapUtils.getDistance(backwardStops.get(i-1).getLocation(), backwardStops.get(i).getLocation());
}
for(int i=1; i< forwardStops.size(); i++){
for(int i=1; i< fSsize; i++){
d += MapUtils.getDistance(forwardStops.get(i-1).getLocation(), forwardStops.get(i).getLocation());
}
return d;
}
}
}

View file

@ -834,13 +834,14 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
}
int j = 0;
for (; j < cities.size(); j++) {
int csize = cities.size();
for (; j < csize; j++) {
City c = cities.get(j);
if (c.getType() != CityType.CITY && c.getType() != CityType.TOWN) {
break;
}
}
progress.startTask(Messages.getString("IndexCreator.SERIALIZING_ADRESS"), j + ((cities.size() - j) / 100 + 1)); //$NON-NLS-1$
progress.startTask(Messages.getString("IndexCreator.SERIALIZING_ADRESS"), j + ((csize - j) / 100 + 1)); //$NON-NLS-1$
Map<String, Set<Street>> postcodes = new TreeMap<String, Set<Street>>();
boolean writeCities = true;
@ -855,7 +856,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
// write cities and after villages
writer.startCityIndexes(false);
for (int i = 0; i < cities.size(); i++) {
for (int i = 0; i < csize; i++) {
City c = cities.get(i);
List<City> listSuburbs = null;
for (City suburb : suburbs) {
@ -868,7 +869,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
}
if (writeCities) {
progress.progress(1);
} else if ((cities.size() - i) % 100 == 0) {
} else if ((csize - i) % 100 == 0) {
progress.progress(1);
}
if (writeCities && c.getType() != CityType.CITY && c.getType() != CityType.TOWN) {
@ -1130,7 +1131,4 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
stat.close();
return cities;
}
}

View file

@ -282,7 +282,8 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator {
List<Way> l = new ArrayList<Way>();
l.add(w);
boolean add = true;
for (int k = 0; k < incompletedRings.size();) {
int iRsize = incompletedRings.size();
for (int k = 0; k < iRsize;) {
boolean remove = false;
List<Way> i = incompletedRings.get(k);
Way last = i.get(i.size() - 1);
@ -576,7 +577,8 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator {
fs.close();
}
List<Node> wNodes = new ArrayList<Node>();
for (int i = 0; i < wayNodes.size(); i += 2) {
int wNsize = wayNodes.size();
for (int i = 0; i < wNsize; i += 2) {
wNodes.add(new Node(wayNodes.get(i), wayNodes.get(i + 1), i == 0 ? startNode : endNode));
}
boolean skip = false;
@ -605,7 +607,8 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator {
int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
int c = 0;
for (int i = 0; i < nodes.size(); i++) {
int nsize = nodes.size();
for (int i = 0; i < nsize; i++) {
if (nodes.get(i) != null) {
c++;
int x = (int) (MapUtils.getTileNumberX(zoom, nodes.get(i).getLongitude()) * 256d);

View file

@ -88,11 +88,11 @@ public class Way extends Entity {
} else {
nodes.clear();
}
for (int i = 0; i < nodeIds.size(); i++) {
int nIsize = nodeIds.size();
for (int i = 0; i < nIsize; i++) {
nodes.add((Node) entities.get(new EntityId(EntityType.NODE,nodeIds.get(i))));
}
}
}
@Override

View file

@ -385,7 +385,8 @@ public class OsmBaseStorage extends DefaultHandler {
@Override
protected void parseNodes(List<crosby.binary.Osmformat.Node> n) {
EntityInfo info = null;
for(int i=0; i<n.size(); i++){
int nsize = n.size();
for(int i=0; i<nsize; i++){
crosby.binary.Osmformat.Node nod = n.get(i);
Node e = new Node(parseLat(nod.getLat()), parseLon(nod.getLon()), nod.getId());
for(int j=0; j<nod.getKeysCount(); j++){
@ -398,13 +399,14 @@ public class OsmBaseStorage extends DefaultHandler {
}
registerEntity(EntityType.NODE, e, info);
}
updateProgress(n.size());
updateProgress(nsize);
}
@Override
protected void parseRelations(List<crosby.binary.Osmformat.Relation> r) {
EntityInfo info = null;
for(int i=0; i<r.size(); i++){
int rsize = r.size();
for(int i=0; i<rsize; i++){
crosby.binary.Osmformat.Relation rel = r.get(i);
Relation e = new Relation(rel.getId());
long id = 0;
@ -430,13 +432,14 @@ public class OsmBaseStorage extends DefaultHandler {
}
registerEntity(EntityType.RELATION, e, info);
}
updateProgress(r.size());
updateProgress(rsize);
}
@Override
protected void parseWays(List<crosby.binary.Osmformat.Way> w) {
EntityInfo info = null;
for(int i=0; i<w.size(); i++){
int wsize = w.size();
for(int i=0; i<wsize; i++){
crosby.binary.Osmformat.Way way = w.get(i);
Way e = new Way(way.getId());
long id = 0;
@ -454,7 +457,7 @@ public class OsmBaseStorage extends DefaultHandler {
}
registerEntity(EntityType.WAY, e, info);
}
updateProgress(w.size());
updateProgress(wsize);
}
@Override

View file

@ -126,7 +126,8 @@ public class MinskTransReader {
Map<String, Node> correlated = new LinkedHashMap<String, Node>();
Map<Node, String> reverse = new LinkedHashMap<Node, String>();
List<TransportStop> stopsToCheck = new ArrayList<TransportStop>(stopsMap.values());
for(int k =0; k<stopsToCheck.size(); k++){
int sTCsize = stopsToCheck.size();
for(int k =0; k<sTCsize; k++){
TransportStop r = stopsToCheck.get(k);
List<Node> closestObjects = busStops.getClosestObjects(r.latitude, r.longitude, 0, 1);
// filter closest objects
@ -140,7 +141,8 @@ public class MinskTransReader {
MapUtils.sortListOfEntities(closestObjects, r.latitude, r.longitude);
int ind = 0;
boolean ccorrelated = false;
while(ind < closestObjects.size() && !ccorrelated){
int cOsize = closestObjects.size();
while(ind < cOsize && !ccorrelated){
Node foundNode = closestObjects.get(ind);
if(!reverse.containsKey(foundNode)){
// all is good no one registered to that stop
@ -279,7 +281,8 @@ public class MinskTransReader {
list.add(0, end);
list.add(start);
}
for(int i=0; i<list.size(); i++){
int lsize = list.size();
for(int i=0; i<lsize; i++){
String st = route.routeStops.get(i);
Node correlatedNode = correlated.get(st);
TransportStop trStop = trStops.get(st);
@ -294,7 +297,7 @@ public class MinskTransReader {
} else if(correlatedNode.getId() != e.getId()){
double dist = MapUtils.getDistance(correlatedNode, e.getLatLon());
if(i==list.size() - 1 && !direct && dist < 150){
if(i==lsize - 1 && !direct && dist < 150){
continue;
}
String eStop = e.getId() + " " + e.getTag(OSMTagKey.NAME);
@ -360,7 +363,8 @@ public class MinskTransReader {
Relation relation = checkedRoutes.get(s);
// correlating stops
for (int i = 0; i < r.routeStops.size(); i++) {
int rSsize = r.routeStops.size();
for (int i = 0; i < rSsize; i++) {
String stop = r.routeStops.get(i);
if (!stopsMap.containsKey(stop)) {
throw new IllegalArgumentException("Stops file is not corresponded to routes file");
@ -379,7 +383,7 @@ public class MinskTransReader {
System.out.println("[ADD] Added new bus_stop : " + node.getId() + " " + st.name + " minsktrans_stop_id " + st.stopId);
correlated.put(stop, node);
}
if (i == 0 || i == r.routeStops.size() - 1) {
if (i == 0 || i == rSsize - 1) {
if (direct) {
relation.addMember(correlated.get(stop).getId(), EntityType.NODE, "stop");
}