Oid: avoid unnecessary copy

Going through GoByte() means we allocate and copy an extra slice that we
just use in order to call copy(). Use memcpy() instead to copy directly
from the git_oid to the Oid.
This commit is contained in:
Carlos Martín Nieto 2014-03-21 07:42:36 +01:00
parent 574f0dd12d
commit a333fd9a49
1 changed files with 3 additions and 2 deletions

5
git.go
View File

@ -3,7 +3,7 @@ package git
/*
#cgo pkg-config: libgit2
#include <git2.h>
#include <git2/errors.h>
#include <string.h>
*/
import "C"
import (
@ -38,7 +38,8 @@ func newOidFromC(coid *C.git_oid) *Oid {
}
oid := new(Oid)
copy(oid[0:20], C.GoBytes(unsafe.Pointer(coid), 20))
C.memcpy(unsafe.Pointer(oid), unsafe.Pointer(coid), 20)
return oid
}