summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Harris <git@peter.is-a-geek.org>2010-12-28 20:38:54 -0500
committerPeter Harris <git@peter.is-a-geek.org>2010-12-28 20:38:54 -0500
commit60c503d7058fcc644db838ae0ffbefcf87409ed3 (patch)
tree389970f757f7a407b741f2726740dd88e8ab4a88
parent5bfc4aa02f512c21ef494f3fba387721153f5cce (diff)
Stop using defer when it isn't needed
It's a powerful construct, but it cuts the speed of noop.go in half. That's a steep penalty when none of the functions return (and none should panic). Now pushing 2.2M noop/sec
-rw-r--r--xgob.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/xgob.go b/xgob.go
index cfd5f2e..9211408 100644
--- a/xgob.go
+++ b/xgob.go
@@ -264,17 +264,16 @@ func (c *Connection) fullSeq(seq uint16) uint64 {
func (c *Connection) registerReply (reply chan interface{}) {
c.replyMutex.Lock()
- defer c.replyMutex.Unlock()
c.lastRequestWritten++
if reply != nil {
c.reply[c.lastRequestWritten] = reply
}
+ c.replyMutex.Unlock()
}
func (c *Connection) postReply (seq uint64, reply interface{}) {
c.replyMutex.Lock()
- defer c.replyMutex.Unlock()
if seq != c.lastSequenceRead {
c.reply[c.lastSequenceRead] = nil, false
@@ -297,6 +296,8 @@ func (c *Connection) postReply (seq uint64, reply interface{}) {
}
}
c.lastSequenceRead = seq
+
+ c.replyMutex.Unlock()
}
func (c *Connection) read (in *bufio.Reader) {
@@ -377,7 +378,6 @@ func (c *Connection) Disconnect () {
func (c *Connection) writeRequest (req []byte, replier bool, rv chan interface{}) {
c.writeMutex.Lock()
- defer c.writeMutex.Unlock()
c.registerReply(rv)
c.out.Write(req)
@@ -391,6 +391,7 @@ func (c *Connection) writeRequest (req []byte, replier bool, rv chan interface{}
c.lastReplierSent = c.lastRequestWritten
}
}
+ c.writeMutex.Unlock()
}
func (c *Connection) WriteMultiRequest (req []byte, expected int) chan interface{} {
@@ -429,9 +430,8 @@ func (c *Connection) Flush () {
}
c.writeMutex.Lock()
- defer c.writeMutex.Unlock()
-
c.out.Flush()
+ c.writeMutex.Unlock()
}
func (c *Connection) HasError () bool {