Commit de0799bb authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Small performance optimizations.

parent c1a117cc
......@@ -94,12 +94,12 @@ func (c *FileSystemConnector) childLookup(out *raw.EntryOut, fsi FsNode) {
func (c *FileSystemConnector) findMount(parent *Inode, name string) (mount *fileSystemMount) {
parent.treeLock.RLock()
defer parent.treeLock.RUnlock()
if parent.mounts == nil {
return nil
if parent.mounts != nil {
mount = parent.mounts[name]
}
parent.treeLock.RUnlock()
return parent.mounts[name]
return
}
func (c *FileSystemConnector) toInode(nodeid uint64) *Inode {
......
......@@ -75,9 +75,9 @@ func CheckSuccess(e error) {
}
// Thanks to Andrew Gerrand for this hack.
func asSlice(ptr unsafe.Pointer, byteCount uintptr) []byte {
h := &reflect.SliceHeader{uintptr(ptr), int(byteCount), int(byteCount)}
return *(*[]byte)(unsafe.Pointer(h))
func toSlice(dest *[]byte, ptr unsafe.Pointer, byteCount uintptr) {
h := (*reflect.SliceHeader)(unsafe.Pointer(dest))
*h = reflect.SliceHeader{uintptr(ptr), int(byteCount), int(byteCount)}
}
func Version() string {
......
......@@ -295,8 +295,6 @@ func (ms *MountState) loop(exitIdle bool) {
}
func (ms *MountState) handleRequest(req *request) {
defer ms.returnRequest(req)
req.parse()
if req.handler == nil {
req.status = ENOSYS
......@@ -320,6 +318,7 @@ func (ms *MountState) handleRequest(req *request) {
log.Printf("writer: Write/Writev failed, err: %v. opcode: %v",
errNo, operationName(req.inHeader.Opcode))
}
ms.returnRequest(req)
}
func (ms *MountState) AllocOut(req *request, size uint32) []byte {
......
......@@ -171,7 +171,7 @@ func (r *request) parse() {
}
}
r.outBuf = zeroOutBuf
copy(r.outBuf[:r.handler.OutputSize], zeroOutBuf[:r.handler.OutputSize])
r.outData = unsafe.Pointer(&r.outBuf[sizeOfOutHeader])
}
......@@ -189,7 +189,9 @@ func (r *request) serialize() (header []byte, data []byte) {
o.Length = uint32(
int(sizeOfOutHeader) + int(dataLength) + int(len(r.flatData)))
copy(header[sizeOfOutHeader:], asSlice(r.outData, dataLength))
var asSlice []byte
toSlice(&asSlice, r.outData, dataLength)
copy(header[sizeOfOutHeader:], asSlice)
return header, r.flatData
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment