diff options
author | Peter Harris <git@peter.is-a-geek.org> | 2010-12-28 20:38:54 -0500 |
---|---|---|
committer | Peter Harris <git@peter.is-a-geek.org> | 2010-12-28 20:38:54 -0500 |
commit | 60c503d7058fcc644db838ae0ffbefcf87409ed3 (patch) | |
tree | 389970f757f7a407b741f2726740dd88e8ab4a88 | |
parent | 5bfc4aa02f512c21ef494f3fba387721153f5cce (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.go | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -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 { |