File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,9 @@ func (id ObjectID) Timestamp() time.Time {
61
61
62
62
// Hex returns the hex encoding of the ObjectID as a string.
63
63
func (id ObjectID ) Hex () string {
64
- return hex .EncodeToString (id [:])
64
+ var buf [24 ]byte
65
+ hex .Encode (buf [:], id [:])
66
+ return string (buf [:])
65
67
}
66
68
67
69
func (id ObjectID ) String () string {
Original file line number Diff line number Diff line change @@ -28,6 +28,13 @@ func TestString(t *testing.T) {
28
28
require .Contains (t , id .String (), id .Hex ())
29
29
}
30
30
31
+ func BenchmarkHex (b * testing.B ) {
32
+ id := NewObjectID ()
33
+ for i := 0 ; i < b .N ; i ++ {
34
+ id .Hex ()
35
+ }
36
+ }
37
+
31
38
func TestFromHex_RoundTrip (t * testing.T ) {
32
39
before := NewObjectID ()
33
40
after , err := ObjectIDFromHex (before .Hex ())
You can’t perform that action at this time.
0 commit comments