logo separator

[mkgmap-dev] [PATCH 12/14] Add in some specialcase serialization code for a 15-30% speedup.

From Jeffrey C. Ollie jeff at ocjtech.us on Thu Sep 9 21:12:12 BST 2010

From: Scott Crosby <scrosby at cs.rice.edu>

Result is identical numbers but not binary-identical because of
trailing 0 digits in the output.

Speedup is cumulative with binary format and fixed hash table.
---
 src/uk/me/parabola/splitter/OSMWriter.java |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/uk/me/parabola/splitter/OSMWriter.java b/src/uk/me/parabola/splitter/OSMWriter.java
index 03c7d52..c42ce52 100644
--- a/src/uk/me/parabola/splitter/OSMWriter.java
+++ b/src/uk/me/parabola/splitter/OSMWriter.java
@@ -215,7 +215,6 @@ public class OSMWriter {
 		checkFlush(22);
         writeString(Double.toString(value));
 	}
-	
 	/** Write a double truncated to OSM's 7 digits of precision
 	 *
 	 *  TODO: Optimize. Responsible for >30% of the runtime after other using binary 
@@ -223,10 +222,22 @@ public class OSMWriter {
 	 */
 	private void writeDouble(double value) throws IOException {
 		checkFlush(22);
-		writeString(numberFormat.format(value));
-		return;
+		// Punt on some annoying specialcases
+		if (value < -200 || value > 200 || (value > -1 && value < 1))
+			writeString(numberFormat.format(value));
+		else {
+		     if (value < 0) {
+		    	 writeChar('-');
+		    	 value = -value;
+		     }
+
+		int val = (int)Math.round(value*10000000);
+		StringBuilder s = new StringBuilder(Integer.toString(val));
+		s.insert(s.length()-7, '.');
+		writeString(s.toString());
+		}
 	}
-
+	
 	private void writeInt(int value) throws IOException {
 		checkFlush(11);
 		index += Convert.intToString(value, charBuf, index);
-- 
1.7.2.3




More information about the mkgmap-dev mailing list