optimized map ionization to avoid extra marks

This commit is contained in:
Ondřej Hruška
2014-04-20 04:46:55 +02:00
parent 8872fd3f5f
commit f8f49b81ff
18 changed files with 125 additions and 123 deletions
@@ -725,7 +725,6 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
};
}
/**
@@ -756,7 +755,6 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
};
}
/**
@@ -789,7 +787,6 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
}
public Num x()
{
return p_x != null ? p_x : (p_x = origin().xn());
@@ -1048,5 +1045,5 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
// overflow || intersect
return ((rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry));
}
}
@@ -1,5 +1,6 @@
package mightypork.util.error;
import java.io.IOException;
+17 -3
View File
@@ -3,9 +3,13 @@ package mightypork.util.files.ion;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import mightypork.rogue.world.tile.Tile;
import mightypork.util.error.CorruptedDataException;
import mightypork.util.logging.Log;
@@ -403,11 +407,17 @@ public class Ion {
*/
public static void writeObject(OutputStream out, Object obj) throws IOException
{
if (obj instanceof Tile) throw new IllegalAccessError();
if (obj == null) {
writeMark(out, NULL);
return;
}
if (obj instanceof Ionizable) {
short mark = ((Ionizable) obj).getIonMark();
final short mark = ((Ionizable) obj).getIonMark();
Class<? extends Ionizable> clzRegistered = customIonizables.get(mark);
final Class<? extends Ionizable> clzRegistered = customIonizables.get(mark);
if (clzRegistered == null) {
throw new IOException("Ionizable object not registered: " + Log.str(obj.getClass()));
@@ -1292,6 +1302,10 @@ public class Ion {
public static <K, V> void writeMap(OutputStream out, Map<K, V> map) throws IOException
{
for (final Entry<K, V> e : map.entrySet()) {
if (e.getValue() == null) {
continue;
}
writeMark(out, ENTRY);
writeObject(out, e.getKey());
writeObject(out, e.getValue());
@@ -1,5 +1,6 @@
package mightypork.util.files.ion;
import mightypork.util.files.ion.templates.IonizableHashMap;
+2
View File
@@ -337,6 +337,8 @@ public class Log {
public static String str(Object o)
{
if (o == null) return "<null>";
boolean hasToString = false;
try {