Browse Source

added skip optimization

Nicolas Cannasse 19 years ago
parent
commit
ac02d3a80d
2 changed files with 15 additions and 2 deletions
  1. 6 2
      std/neko/io/FileInput.hx
  2. 9 0
      std/neko/io/StringInput.hx

+ 6 - 2
std/neko/io/FileInput.hx

@@ -63,8 +63,12 @@ class FileInput extends Input {
 		file_close(__f);
 	}
 
-	public function seek( p : Int, pos : FileSeek ) : Int {
-		return file_seek(__f,p,switch( pos ) { case SeekBegin: 0; case SeekCur: 1; case SeekEnd: 2; });
+	public override function skip( nbytes ) {
+		try	seek(nbytes,SeekCur) catch( e : Dynamic ) throw Error.Eof;
+	}
+
+	public function seek( p : Int, pos : FileSeek ) {
+		file_seek(__f,p,switch( pos ) { case SeekBegin: 0; case SeekCur: 1; case SeekEnd: 2; });
 	}
 
 	public function tell() : Int {

+ 9 - 0
std/neko/io/StringInput.hx

@@ -56,4 +56,13 @@ class StringInput extends Input {
 		return blen;
 	}
 
+	public override function skip( nbytes : Int ) {
+		pos += nbytes;
+		len -= nbytes;
+		if( len < 0 ) {
+			len = 0;
+			throw Error.Eof;
+		}
+	}
+
 }