Permalink
Browse files

Use C.GoBytes instead of C.memcpy

I noticed that there was memcpy used a few times where C.GoBytes was more
appropriate.

Also remoted a few unnecessary unsafe.Pointer casts.

Signed-off-by: Ondrej Kupka <ondra.cap@gmail.com>
  • Loading branch information...
1 parent db5ebc6 commit fba6aafbd61ac45d7b739080ee85b4d5646e9480 @tchap tchap committed May 28, 2013
Showing with 4 additions and 6 deletions.
  1. +2 −3 zmq_2_x.go
  2. +2 −3 zmq_3_x.go
View
@@ -63,7 +63,7 @@ func (s *Socket) Send(data []byte, flags SendRecvOption) error {
if size > 0 {
// FIXME Ideally this wouldn't require a copy.
- C.memcpy(unsafe.Pointer(C.zmq_msg_data(&m)), unsafe.Pointer(&data[0]), size) // XXX I hope this works...(seems to)
+ C.memcpy(C.zmq_msg_data(&m), unsafe.Pointer(&data[0]), size) // XXX I hope this works...(seems to)
}
if rc, err := C.zmq_send(s.s, &m, C.int(flags)); rc != 0 {
@@ -95,8 +95,7 @@ func (s *Socket) Recv(flags SendRecvOption) (data []byte, err error) {
// FIXME Ideally this wouldn't require a copy.
size := C.zmq_msg_size(&m)
if size > 0 {
- data = make([]byte, int(size))
- C.memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&m), size)
+ data = C.GoBytes(C.zmq_msg_data(&m), C.int(size))
} else {
data = nil
}
View
@@ -142,7 +142,7 @@ func (s *Socket) Send(data []byte, flags SendRecvOption) error {
if size > 0 {
// FIXME Ideally this wouldn't require a copy.
- C.memcpy(unsafe.Pointer(C.zmq_msg_data(&m)), unsafe.Pointer(&data[0]), size) // XXX I hope this works...(seems to)
+ C.memcpy(C.zmq_msg_data(&m), unsafe.Pointer(&data[0]), size) // XXX I hope this works...(seems to)
}
if rc, err := C.zmq_sendmsg(s.s, &m, C.int(flags)); rc == -1 {
@@ -174,8 +174,7 @@ func (s *Socket) Recv(flags SendRecvOption) (data []byte, err error) {
// FIXME Ideally this wouldn't require a copy.
size := C.zmq_msg_size(&m)
if size > 0 {
- data = make([]byte, int(size))
- C.memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&m), size)
+ data = C.GoBytes(C.zmq_msg_data(&m), C.int(size))
} else {
data = nil
}

0 comments on commit fba6aaf

Please sign in to comment.