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:
parent
574f0dd12d
commit
a333fd9a49
5
git.go
5
git.go
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue