From 24b92b5410b6d8decdd11894fdb54418f0321845 Mon Sep 17 00:00:00 2001 From: Rahul Rampure Date: Wed, 1 Jul 2026 22:15:30 +0530 Subject: [PATCH 1/4] =?UTF-8?q?perf:=20=C2=A722=20replace=20IndexInternalI?= =?UTF-8?q?D.Compare=20=E2=86=92=20binary.BigEndian.Uint64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/index.go b/index.go index 679dd4f..c55dcbd 100644 --- a/index.go +++ b/index.go @@ -15,10 +15,8 @@ package index import ( - "bytes" "context" "encoding/binary" - "fmt" "reflect" ) @@ -221,15 +219,19 @@ func (id IndexInternalID) Equals(other IndexInternalID) bool { // Compare compares two IndexInternalID values, inherently comparing the encoded uint64 values. func (id IndexInternalID) Compare(other IndexInternalID) int { - return bytes.Compare(id, other) + idVal := id.Value() + otherVal := other.Value() + if idVal < otherVal { + return -1 + } else if idVal > otherVal { + return 1 + } + return 0 } // Value returns the uint64 value encoded in the IndexInternalID. -func (id IndexInternalID) Value() (uint64, error) { - if len(id) != 8 { - return 0, fmt.Errorf("wrong len for IndexInternalID: %q", id) - } - return binary.BigEndian.Uint64(id), nil +func (id IndexInternalID) Value() uint64 { + return binary.BigEndian.Uint64(id) } type TermFieldDoc struct { From 182b89ba0178e09e788b9c795b262ebe4b7881cf Mon Sep 17 00:00:00 2001 From: Rahul Rampure Date: Wed, 1 Jul 2026 22:26:00 +0530 Subject: [PATCH 2/4] add a rest method --- index.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.go b/index.go index c55dcbd..55a4842 100644 --- a/index.go +++ b/index.go @@ -234,6 +234,11 @@ func (id IndexInternalID) Value() uint64 { return binary.BigEndian.Uint64(id) } +// Reset replaces the encoded uint64 value in the IndexInternalID with a new value. +func (id IndexInternalID) Reset(in uint64) { + binary.BigEndian.PutUint64(id, in) +} + type TermFieldDoc struct { Term string ID IndexInternalID From 28c482f5d3c763fe4ae44f47279a3aed42a5418b Mon Sep 17 00:00:00 2001 From: Rahul Rampure Date: Thu, 2 Jul 2026 00:17:17 +0530 Subject: [PATCH 3/4] revert --- index.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/index.go b/index.go index 55a4842..c6d3cdf 100644 --- a/index.go +++ b/index.go @@ -15,6 +15,7 @@ package index import ( + "bytes" "context" "encoding/binary" "reflect" @@ -219,14 +220,7 @@ func (id IndexInternalID) Equals(other IndexInternalID) bool { // Compare compares two IndexInternalID values, inherently comparing the encoded uint64 values. func (id IndexInternalID) Compare(other IndexInternalID) int { - idVal := id.Value() - otherVal := other.Value() - if idVal < otherVal { - return -1 - } else if idVal > otherVal { - return 1 - } - return 0 + return bytes.Compare(id, other) } // Value returns the uint64 value encoded in the IndexInternalID. From 106ab4c07bb4fae96dbb3644cd05857af8dae7dd Mon Sep 17 00:00:00 2001 From: Rahul Rampure Date: Thu, 2 Jul 2026 00:33:20 +0530 Subject: [PATCH 4/4] rename API --- index.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.go b/index.go index c6d3cdf..fc12d98 100644 --- a/index.go +++ b/index.go @@ -203,8 +203,9 @@ func NewIndexInternalID(buf []byte, in uint64) IndexInternalID { buf = make([]byte, 8) } } - binary.BigEndian.PutUint64(buf, in) - return buf + id := IndexInternalID(buf) + id.SetValue(in) + return id } // NewIndexInternalIDFrom creates a new IndexInternalID by copying from `other`, reusing `buf` when possible. @@ -228,8 +229,8 @@ func (id IndexInternalID) Value() uint64 { return binary.BigEndian.Uint64(id) } -// Reset replaces the encoded uint64 value in the IndexInternalID with a new value. -func (id IndexInternalID) Reset(in uint64) { +// SetValue overwrites the encoded uint64 value in the IndexInternalID in place. +func (id IndexInternalID) SetValue(in uint64) { binary.BigEndian.PutUint64(id, in) }