use TagSet instead of Tag[] in MapElement

This commit is contained in:
Hannes Janetzek
2013-06-12 02:52:23 +02:00
parent 0ed0d1a154
commit 48369f6baf
11 changed files with 205 additions and 241 deletions

View File

@@ -15,6 +15,7 @@
package org.oscim.theme;
import org.oscim.core.Tag;
import org.oscim.core.TagSet;
class MatchingCacheKey {
int mHash;
@@ -24,34 +25,38 @@ class MatchingCacheKey {
}
MatchingCacheKey(MatchingCacheKey key) {
// need to clone tags as they belong to TileDataSource
mTags = key.mTags.clone();
mTags = key.mTags;
mHash = key.mHash;
}
// set temporary values for comparison
boolean set(Tag[] tags, MatchingCacheKey compare) {
int length = tags.length;
boolean set(TagSet tags, MatchingCacheKey compare) {
int numTags = tags.numTags;
if (compare != null && length == compare.mTags.length) {
if (compare != null && numTags == compare.mTags.length) {
int i = 0;
for (; i < length; i++) {
Tag t1 = tags[i];
for (; i < numTags; i++) {
Tag t1 = tags.tags[i];
Tag t2 = compare.mTags[i];
if (!(t1 == t2 || (t1.key == t2.key && t1.value == t2.value)))
break;
}
if (i == length)
if (i == numTags)
return true;
}
// need to clone tags as they belong to TileDataSource
mTags = new Tag[numTags];
int result = 7;
for (int i = 0; i < length; i++)
result = 31 * result + tags[i].hashCode();
for (int i = 0; i < numTags; i++){
Tag t = tags.tags[i];
result = 31 * result + t.hashCode();
mTags[i] = t;
}
mHash = 31 * result;
mTags = tags;
return false;
}

View File

@@ -105,6 +105,9 @@ public class RenderTheme implements IRenderTheme {
cacheKey = new MatchingCacheKey();
matchType = type;
}
RenderInstructionItem getRenderInstructions(){
return cache.get(cacheKey);
}
}
class RenderInstructionItem {
@@ -200,7 +203,8 @@ public class RenderTheme implements IRenderTheme {
}
if (ri == null) {
ris = cache.cache.get(cache.cacheKey);
// get instruction for current cacheKey
ris = cache.getRenderInstructions();
for (ri = ris; ri != null; ri = ri.next)
if ((ri.zoom & zoomMask) != 0)
@@ -216,7 +220,7 @@ public class RenderTheme implements IRenderTheme {
matches.clear();
for (Rule rule : mRules)
rule.matchElement(cache.matchType, element.tags, zoomMask, matches);
rule.matchElement(cache.matchType, cache.cacheKey.mTags, zoomMask, matches);
int size = matches.size();
if (size > 1) {
@@ -225,7 +229,7 @@ public class RenderTheme implements IRenderTheme {
for (int j = i + 1; j < size; j++) {
if (matches.get(j) == r) {
Log.d(TAG, "fix duplicate instruction! "
+ Arrays.deepToString(element.tags)
+ Arrays.deepToString(cache.cacheKey.mTags)
+ ":" + zoomLevel);
matches.remove(j--);
size--;