Use pointer receiver for large struct (#26668)

Signed-off-by: yah01 <yah2er0ne@outlook.com>
This commit is contained in:
yah01 2023-08-30 10:24:29 +08:00 committed by GitHub
parent b475f25042
commit 213db490bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 26 deletions

View File

@ -93,7 +93,7 @@ type Allocation struct {
ExpireTime Timestamp
}
func (alloc Allocation) String() string {
func (alloc *Allocation) String() string {
t, _ := tsoutil.ParseTS(alloc.ExpireTime)
return fmt.Sprintf("SegmentID: %d, NumOfRows: %d, ExpireTime: %v", alloc.SegmentID, alloc.NumOfRows, t)
}

View File

@ -77,7 +77,7 @@ type FieldData struct {
}
// AsSchemapb converts the FieldData to schemapb.FieldData
func (f FieldData) AsSchemapb() (*schemapb.FieldData, error) {
func (f *FieldData) AsSchemapb() (*schemapb.FieldData, error) {
// is scarlar
ret := schemapb.FieldData{
Type: f.Type,
@ -319,16 +319,16 @@ type VectorsArray struct {
IDs *VectorIDs `json:"ids,omitempty"`
}
func (v VectorsArray) isIDs() bool {
func (v *VectorsArray) isIDs() bool {
return v.IDs != nil
}
func (v VectorsArray) isBinaryVector() bool {
func (v *VectorsArray) isBinaryVector() bool {
return v.IDs == nil && len(v.BinaryVectors) > 0
}
// AsPbVectorArray convert as milvuspb.VectorArray
func (v VectorsArray) AsPbVectorArray() *milvuspb.VectorsArray {
func (v *VectorsArray) AsPbVectorArray() *milvuspb.VectorsArray {
ret := &milvuspb.VectorsArray{}
switch {
case v.isIDs():

View File

@ -10,11 +10,11 @@ type Alias struct {
DbID int64
}
func (a Alias) Available() bool {
func (a *Alias) Available() bool {
return a.State == pb.AliasState_AliasCreated
}
func (a Alias) Clone() *Alias {
func (a *Alias) Clone() *Alias {
return &Alias{
Name: a.Name,
CollectionID: a.CollectionID,
@ -24,7 +24,7 @@ func (a Alias) Clone() *Alias {
}
}
func (a Alias) Equal(other Alias) bool {
func (a *Alias) Equal(other Alias) bool {
return a.Name == other.Name &&
a.CollectionID == other.CollectionID &&
a.DbID == other.DbID

View File

@ -29,11 +29,11 @@ type Collection struct {
EnableDynamicField bool
}
func (c Collection) Available() bool {
func (c *Collection) Available() bool {
return c.State == pb.CollectionState_CollectionCreated
}
func (c Collection) Clone() *Collection {
func (c *Collection) Clone() *Collection {
return &Collection{
TenantID: c.TenantID,
DBID: c.DBID,
@ -56,14 +56,14 @@ func (c Collection) Clone() *Collection {
}
}
func (c Collection) GetPartitionNum(filterUnavailable bool) int {
func (c *Collection) GetPartitionNum(filterUnavailable bool) int {
if !filterUnavailable {
return len(c.Partitions)
}
return lo.CountBy(c.Partitions, func(p *Partition) bool { return p.Available() })
}
func (c Collection) Equal(other Collection) bool {
func (c *Collection) Equal(other Collection) bool {
return c.TenantID == other.TenantID &&
c.DBID == other.DBID &&
CheckPartitionsEqual(c.Partitions, other.Partitions) &&

View File

@ -28,11 +28,11 @@ func NewDefaultDatabase() *Database {
return NewDatabase(util.DefaultDBID, util.DefaultDBName, pb.DatabaseState_DatabaseCreated)
}
func (c Database) Available() bool {
func (c *Database) Available() bool {
return c.State == pb.DatabaseState_DatabaseCreated
}
func (c Database) Clone() *Database {
func (c *Database) Clone() *Database {
return &Database{
TenantID: c.TenantID,
ID: c.ID,
@ -42,7 +42,7 @@ func (c Database) Clone() *Database {
}
}
func (c Database) Equal(other Database) bool {
func (c *Database) Equal(other Database) bool {
return c.TenantID == other.TenantID &&
c.Name == other.Name &&
c.ID == other.ID &&

View File

@ -22,11 +22,11 @@ type Field struct {
DefaultValue *schemapb.ValueField
}
func (f Field) Available() bool {
func (f *Field) Available() bool {
return f.State == schemapb.FieldState_FieldCreated
}
func (f Field) Clone() *Field {
func (f *Field) Clone() *Field {
return &Field{
FieldID: f.FieldID,
Name: f.Name,
@ -56,7 +56,7 @@ func checkParamsEqual(paramsA, paramsB []*commonpb.KeyValuePair) bool {
return A.Equal(paramsB)
}
func (f Field) Equal(other Field) bool {
func (f *Field) Equal(other Field) bool {
return f.FieldID == other.FieldID &&
f.Name == other.Name &&
f.IsPrimaryKey == other.IsPrimaryKey &&

View File

@ -14,11 +14,11 @@ type Partition struct {
State pb.PartitionState
}
func (p Partition) Available() bool {
func (p *Partition) Available() bool {
return p.State == pb.PartitionState_PartitionCreated
}
func (p Partition) Clone() *Partition {
func (p *Partition) Clone() *Partition {
return &Partition{
PartitionID: p.PartitionID,
PartitionName: p.PartitionName,
@ -37,7 +37,7 @@ func ClonePartitions(partitions []*Partition) []*Partition {
return clone
}
func (p Partition) Equal(other Partition) bool {
func (p *Partition) Equal(other Partition) bool {
return p.PartitionName == other.PartitionName
}

View File

@ -31,7 +31,7 @@ func getLoggerOfClientInfo(info *commonpb.ClientInfo) []zap.Field {
return fields
}
func (c clientInfo) getLogger() []zap.Field {
func (c *clientInfo) getLogger() []zap.Field {
fields := getLoggerOfClientInfo(c.ClientInfo)
fields = append(fields,
zap.Int64("identifier", c.identifier),
@ -40,10 +40,10 @@ func (c clientInfo) getLogger() []zap.Field {
return fields
}
func (c clientInfo) ctxLogRegister(ctx context.Context) {
func (c *clientInfo) ctxLogRegister(ctx context.Context) {
log.Ctx(ctx).Info("client register", c.getLogger()...)
}
func (c clientInfo) logDeregister() {
func (c *clientInfo) logDeregister() {
log.Info("client deregister", c.getLogger()...)
}

View File

@ -32,7 +32,7 @@ type SegmentAssignPlan struct {
To int64
}
func (segPlan SegmentAssignPlan) ToString() string {
func (segPlan *SegmentAssignPlan) ToString() string {
return fmt.Sprintf("SegmentPlan:[collectionID: %d, replicaID: %d, segmentID: %d, from: %d, to: %d]\n",
segPlan.Segment.CollectionID, segPlan.ReplicaID, segPlan.Segment.ID, segPlan.From, segPlan.To)
}
@ -44,7 +44,7 @@ type ChannelAssignPlan struct {
To int64
}
func (chanPlan ChannelAssignPlan) ToString() string {
func (chanPlan *ChannelAssignPlan) ToString() string {
return fmt.Sprintf("ChannelPlan:[collectionID: %d, channel: %s, replicaID: %d, from: %d, to: %d]\n",
chanPlan.Channel.CollectionID, chanPlan.Channel.ChannelName, chanPlan.ReplicaID, chanPlan.From, chanPlan.To)
}