about summary refs log tree commit diff
path: root/src/nix-worker/nix-worker.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2011-12-16T21·29+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2011-12-16T21·29+0000
commit8d3dfa2c1782e955d2b7796d19dc0d0381596b98 (patch)
tree2898bece03be625f8899e78789c958274c0b67fe /src/nix-worker/nix-worker.cc
parente0bd307802d13476055f8ba99ab7808de0fd71e5 (diff)
* Avoid expensive conversions from char arrays to STL strings.
Diffstat (limited to 'src/nix-worker/nix-worker.cc')
-rw-r--r--src/nix-worker/nix-worker.cc15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc
index 695e4c38d5..85e2105b27 100644
--- a/src/nix-worker/nix-worker.cc
+++ b/src/nix-worker/nix-worker.cc
@@ -56,7 +56,7 @@ static void tunnelStderr(const unsigned char * buf, size_t count)
     if (canSendStderr && myPid == getpid()) {
         try {
             writeInt(STDERR_NEXT, to);
-            writeString(string((char *) buf, count), to);
+            writeString(buf, count, to);
             to.flush();
         } catch (...) {
             /* Write failed; that means that the other side is
@@ -205,7 +205,7 @@ struct TunnelSink : Sink
     virtual void operator () (const unsigned char * data, size_t len)
     {
         writeInt(STDERR_WRITE, to);
-        writeString(string((const char *) data, len), to);
+        writeString(data, len, to);
     }
 };
 
@@ -224,16 +224,11 @@ struct TunnelSource : BufferedSource
         writeInt(STDERR_READ, to);
         writeInt(len, to);
         to.flush();
-        string s = readString(from); // !!! inefficient
+        size_t n = readString(data, len, from);
 
         startWork();
-
-        if (s.empty()) throw EndOfFile("unexpected end-of-file");
-        if (s.size() > len) throw Error("client sent too much data");
-
-        memcpy(data, (const unsigned char *) s.c_str(), s.size());
-
-        return s.size();
+        if (n == 0) throw EndOfFile("unexpected end-of-file");
+        return n;
     }
 };