Changeset 3158 in josm


Ignore:
Timestamp:
2010-03-27T17:53:47+01:00 (14 years ago)
Author:
jttt
Message:

Use simple casting instead of Math.floor(). Should do the same thing for this number range and it's much faster. Fixed return value of Storage.add()

Location:
trunk/src/org/openstreetmap/josm/data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/QuadTiling.java

    r3145 r3158  
    6969    {
    7070        //return Math.round((lon + 180.0) * QuadBuckets.WORLD_PARTS / 360.0)-1;
    71         long ret = (long)Math.floor((lon + 180.0) * WORLD_PARTS / 360.0);
     71        long ret = (long)((lon + 180.0) * WORLD_PARTS / 360.0);
    7272        if (ret == WORLD_PARTS) {
    7373            ret--;
     
    7878    {
    7979        //return Math.round((lat + 90.0) * QuadBuckets.WORLD_PARTS / 180.0)-1;
    80         long ret = (long)Math.floor((lat + 90.0) * WORLD_PARTS / 180.0);
     80        long ret = (long)((lat + 90.0) * WORLD_PARTS / 180.0);
    8181        if (ret == WORLD_PARTS) {
    8282            ret--;
  • trunk/src/org/openstreetmap/josm/data/osm/Storage.java

    r3083 r3158  
    8282 * assert things.get(new Thing(3)) == fk.get(3);
    8383 * </pre></li>
    84 *
     84 *
    8585 *
    8686 * @author nenik
     
    114114
    115115    // --------------- Collection implementation ------------------------
     116    @Override
    116117    public int size() {
    117118        return size;
    118119    }
    119120
     121    @Override
    120122    public Iterator<T> iterator() {
    121123        return new Iter();
     
    129131    public @Override boolean add(T t) {
    130132        T orig = putUnique(t);
    131         return orig != t;
     133        return orig == t;
    132134    }
    133135
     
    140142        modCount++;
    141143        size = 0;
    142         for (int i = 0; i<data.length; i++) data[i] = null;
     144        for (int i = 0; i<data.length; i++) {
     145            data[i] = null;
     146        }
    143147    }
    144148
    145149    public @Override int hashCode() {
    146150        int h = 0;
    147         for (T t : this) h += hash.getHashCode(t);
     151        for (T t : this) {
     152            h += hash.getHashCode(t);
     153        }
    148154        return h;
    149155    }
     
    220226        int bucket = hcode & mask;
    221227        while ((entry = (T)data[bucket]) != null) {
    222             if (ha.equals(key, entry)) {
     228            if (ha.equals(key, entry))
    223229                return bucket;
    224             }
    225230            bucket = (bucket+1) & mask;
    226231        }
     
    265270
    266271            for (Object o : data) {
    267                 if (o == null) continue;
     272                if (o == null) {
     273                    continue;
     274                }
    268275                int bucket = rehash(hash.getHashCode((T)o)) & nMask;
    269                 while (big[bucket] != null) bucket = (bucket+1) & nMask;
     276                while (big[bucket] != null) {
     277                    bucket = (bucket+1) & nMask;
     278                }
    270279                big[bucket] = o;
    271280            }
     
    292301        };
    293302    }
    294 /*
     303    /*
    295304    public static <O> Hash<O,O> identityHash() {
    296305        return new Hash<O,O>() {
     
    303312        };
    304313    }
    305 */
     314     */
    306315
    307316    private class FMap<K> implements Map<K,T> {
     
    350359                Storage.this.addAll(((Storage.FMap)m).values());
    351360            } else {
    352                 for (Map.Entry<? extends K, ? extends T> e : m.entrySet())
     361                for (Map.Entry<? extends K, ? extends T> e : m.entrySet()) {
    353362                    put(e.getKey(), e.getValue());
     363                }
    354364            }
    355365        }
     
    402412        private void align() {
    403413            if (mods != modCount) throw new ConcurrentModificationException();
    404             while (slot < data.length && data[slot] == null) slot++;
     414            while (slot < data.length && data[slot] == null) {
     415                slot++;
     416            }
    405417        }
    406418    }
Note: See TracChangeset for help on using the changeset viewer.