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) { ...@@ -94,12 +94,12 @@ func (c *FileSystemConnector) childLookup(out *raw.EntryOut, fsi FsNode) {
func (c *FileSystemConnector) findMount(parent *Inode, name string) (mount *fileSystemMount) { func (c *FileSystemConnector) findMount(parent *Inode, name string) (mount *fileSystemMount) {
parent.treeLock.RLock() parent.treeLock.RLock()
defer parent.treeLock.RUnlock() if parent.mounts != nil {
if parent.mounts == nil { mount = parent.mounts[name]
return nil
} }
parent.treeLock.RUnlock()
return parent.mounts[name] return
} }
func (c *FileSystemConnector) toInode(nodeid uint64) *Inode { func (c *FileSystemConnector) toInode(nodeid uint64) *Inode {
......
...@@ -75,9 +75,9 @@ func CheckSuccess(e error) { ...@@ -75,9 +75,9 @@ func CheckSuccess(e error) {
} }
// Thanks to Andrew Gerrand for this hack. // Thanks to Andrew Gerrand for this hack.
func asSlice(ptr unsafe.Pointer, byteCount uintptr) []byte { func toSlice(dest *[]byte, ptr unsafe.Pointer, byteCount uintptr) {
h := &reflect.SliceHeader{uintptr(ptr), int(byteCount), int(byteCount)} h := (*reflect.SliceHeader)(unsafe.Pointer(dest))
return *(*[]byte)(unsafe.Pointer(h)) *h = reflect.SliceHeader{uintptr(ptr), int(byteCount), int(byteCount)}
} }
func Version() string { func Version() string {
......
...@@ -295,8 +295,6 @@ func (ms *MountState) loop(exitIdle bool) { ...@@ -295,8 +295,6 @@ func (ms *MountState) loop(exitIdle bool) {
} }
func (ms *MountState) handleRequest(req *request) { func (ms *MountState) handleRequest(req *request) {
defer ms.returnRequest(req)
req.parse() req.parse()
if req.handler == nil { if req.handler == nil {
req.status = ENOSYS req.status = ENOSYS
...@@ -320,6 +318,7 @@ func (ms *MountState) handleRequest(req *request) { ...@@ -320,6 +318,7 @@ func (ms *MountState) handleRequest(req *request) {
log.Printf("writer: Write/Writev failed, err: %v. opcode: %v", log.Printf("writer: Write/Writev failed, err: %v. opcode: %v",
errNo, operationName(req.inHeader.Opcode)) errNo, operationName(req.inHeader.Opcode))
} }
ms.returnRequest(req)
} }
func (ms *MountState) AllocOut(req *request, size uint32) []byte { func (ms *MountState) AllocOut(req *request, size uint32) []byte {
......
...@@ -171,7 +171,7 @@ func (r *request) parse() { ...@@ -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]) r.outData = unsafe.Pointer(&r.outBuf[sizeOfOutHeader])
} }
...@@ -189,7 +189,9 @@ func (r *request) serialize() (header []byte, data []byte) { ...@@ -189,7 +189,9 @@ func (r *request) serialize() (header []byte, data []byte) {
o.Length = uint32( o.Length = uint32(
int(sizeOfOutHeader) + int(dataLength) + int(len(r.flatData))) 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 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