changeset 1436:65d4afc9ad07

cache fix
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 06 Jan 2020 18:17:46 -0700
parents 3aae37efbf40
children 3e185b27f982
files src/luan/cmd_line.luan src/luan/impl/Compiled.java
diffstat 2 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/cmd_line.luan	Mon Jan 06 17:47:10 2020 -0700
+++ b/src/luan/cmd_line.luan	Mon Jan 06 18:17:46 2020 -0700
@@ -8,6 +8,7 @@
 local unpack = Table.unpack or error()
 local Io = require "luan:Io.luan"
 local print = Io.print or error()
+local Logging = require "luan:logging/Logging.luan"
 
 
 local args = {...}
--- a/src/luan/impl/Compiled.java	Mon Jan 06 17:47:10 2020 -0700
+++ b/src/luan/impl/Compiled.java	Mon Jan 06 18:17:46 2020 -0700
@@ -131,7 +131,7 @@
 	}
 
 
-	private static final int VERSION = 1;
+	private static final int VERSION = 2;
 	private static final File tmpDir;
 	static {
 		File f = new File(System.getProperty("java.io.tmpdir"));
@@ -141,6 +141,24 @@
 			throw new RuntimeException();
 	}
 
+	static void writeLongString(DataOutputStream out,String s) throws IOException {
+		int n = s.length()/0xFFFF;
+		out.writeInt(n+1);
+		for( int i=0; i<n; i++ ) {
+			out.writeUTF( s.substring(i*0xFFFF,(i+1)*0xFFFF) );
+		}
+		out.writeUTF( s.substring(n*0xFFFF) );
+	}
+
+	static String readLongString(DataInputStream in) throws IOException {
+		StringBuilder sb = new StringBuilder();
+		int n = in.readInt();
+		for( int i=0; i<n; i++ ) {
+			sb.append( in.readUTF() );
+		}
+		return sb.toString();
+	}
+
 	static Compiled load(String fileName,String key) {
 		try {
 			File f = new File(tmpDir,fileName);
@@ -149,7 +167,7 @@
 			DataInputStream in = new DataInputStream(new FileInputStream(f));
 			if( in.readInt() != VERSION )
 				return null;
-			if( !in.readUTF().equals(key) )
+			if( !readLongString(in).equals(key) )
 				return null;
 			String className = in.readUTF();
 			int n = in.readInt();
@@ -174,7 +192,7 @@
 			File f = new File(tmpDir,fileName);
 			DataOutputStream out = new DataOutputStream(new FileOutputStream(f));
 			out.writeInt(VERSION);
-			out.writeUTF(key);
+			writeLongString(out,key);
 			out.writeUTF(className);
 			out.writeInt(map.size());
 			for( Map.Entry<String,byte[]> entry : map.entrySet() ) {