1
0
mirror of https://github.com/pfusik/xasm.git synced 2024-06-07 11:29:32 +00:00

Improve I/O performance on Windows (especially network drives).

Reported by Marek Pavlik.
This commit is contained in:
Piotr Fusik 2014-09-26 16:42:54 +02:00
parent 8c6ff185af
commit 5680efc7f5

46
xasm.d
View File

@ -28,6 +28,13 @@ version (Windows) {
extern (Windows) HANDLE GetStdHandle(DWORD nStdHandle); extern (Windows) HANDLE GetStdHandle(DWORD nStdHandle);
} }
int readByte(File *file) {
char c;
if (file.readf("%c", &c) != 1)
return -1;
return c;
}
const string TITLE = "xasm 3.1.0"; const string TITLE = "xasm 3.1.0";
string sourceFilename = null; string sourceFilename = null;
@ -1175,10 +1182,8 @@ void objectByte(ubyte b) {
if (!getOption('q')) if (!getOption('q'))
writeln("Writing object file..."); writeln("Writing object file...");
} }
ubyte[1] buffer;
buffer[0] = b;
try { try {
objectStream.rawWrite(buffer); objectStream.write(cast(char) b);
} catch (Exception e) { } catch (Exception e) {
throw new AssemblyError("Error writing object file"); throw new AssemblyError("Error writing object file");
} }
@ -2288,17 +2293,13 @@ void assemblyIns() {
if (inOpcode) if (inOpcode)
length = 1; length = 1;
while (length != 0) { while (length != 0) {
ubyte[1] buffer; int b = readByte(&stream);
try { if (b < 0) {
if (stream.rawRead(buffer) == null) { if (length > 0)
if (length > 0) throw new AssemblyError("File is too short");
throw new AssemblyError("File is too short"); break;
break;
}
} catch (Exception e) {
throw new AssemblyError("Error reading file");
} }
putByte(buffer[0]); putByte(cast(ubyte) b);
if (length > 0) length--; if (length > 0) length--;
} }
} }
@ -2793,25 +2794,26 @@ void assemblyFile(string filename) {
foundEnd = false; foundEnd = false;
line = ""; line = "";
readChar: while (!foundEnd) { readChar: while (!foundEnd) {
ubyte[1] buffer; int b = readByte(&stream);
if (stream.rawRead(buffer) == null) switch (b) {
break; case -1:
switch (buffer[0]) { break readChar;
case '\r': case '\r':
assemblyLine(); assemblyLine();
line = ""; line = "";
if (stream.rawRead(buffer) == null) b = readByte(&stream);
if (b < 0)
break readChar; break readChar;
if (buffer[0] != '\n') if (b != '\n')
line ~= cast(char) buffer[0]; line ~= cast(char) b;
break; break;
case '\n': case '\n':
case '\x9b': case 0x9b:
assemblyLine(); assemblyLine();
line = ""; line = "";
break; break;
default: default:
line ~= cast(char) buffer[0]; line ~= cast(char) b;
break; break;
} }
} }