Copilot commented on code in PR #888:
URL: 
https://github.com/apache/skywalking-banyandb/pull/888#discussion_r2609280080


##########
banyand/liaison/grpc/locator.go:
##########
@@ -0,0 +1,120 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package grpc
+
+import (
+       "github.com/apache/skywalking-banyandb/api/common"
+       databasev1 
"github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
+       modelv1 
"github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
+       "github.com/apache/skywalking-banyandb/pkg/partition"
+       pbv1 "github.com/apache/skywalking-banyandb/pkg/pb/v1"
+)
+
+type tagFamilySpec interface {
+       GetName() string
+       GetTagNames() []string
+}
+
+type specLocator struct {
+       tagLocators []partition.TagLocator
+}
+
+func newSpecLocator[T tagFamilySpec](schemaFamilies 
[]*databasev1.TagFamilySpec, tagNames []string, specFamilies []T) *specLocator {
+       specFamilyMap, specTagMaps := buildSpecMaps(specFamilies)
+       locator := make([]partition.TagLocator, 0, len(tagNames))
+       for _, tagName := range tagNames {
+               familyIdx, tagIdx := findTagInSpec(schemaFamilies, tagName, 
specFamilyMap, specTagMaps)
+               locator = append(locator, partition.TagLocator{FamilyOffset: 
familyIdx, TagOffset: tagIdx})
+       }
+       return &specLocator{tagLocators: locator}
+}
+
+func buildSpecMaps[T tagFamilySpec](specFamilies []T) (map[string]int, 
map[string]map[string]int) {
+       specFamilyMap := make(map[string]int)
+       specTagMaps := make(map[string]map[string]int)

Review Comment:
   The maps should be initialized with capacity hints based on the spec 
families length for better performance. `specFamilyMap` should use 
`make(map[string]int, len(specFamilies))` and `specTagMaps` should use 
`make(map[string]map[string]int, len(specFamilies))`.
   ```suggestion
        specFamilyMap := make(map[string]int, len(specFamilies))
        specTagMaps := make(map[string]map[string]int, len(specFamilies))
   ```



##########
banyand/liaison/grpc/locator.go:
##########
@@ -0,0 +1,120 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package grpc
+
+import (
+       "github.com/apache/skywalking-banyandb/api/common"
+       databasev1 
"github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
+       modelv1 
"github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
+       "github.com/apache/skywalking-banyandb/pkg/partition"
+       pbv1 "github.com/apache/skywalking-banyandb/pkg/pb/v1"
+)
+
+type tagFamilySpec interface {
+       GetName() string
+       GetTagNames() []string
+}
+
+type specLocator struct {
+       tagLocators []partition.TagLocator
+}
+
+func newSpecLocator[T tagFamilySpec](schemaFamilies 
[]*databasev1.TagFamilySpec, tagNames []string, specFamilies []T) *specLocator {
+       specFamilyMap, specTagMaps := buildSpecMaps(specFamilies)
+       locator := make([]partition.TagLocator, 0, len(tagNames))
+       for _, tagName := range tagNames {
+               familyIdx, tagIdx := findTagInSpec(schemaFamilies, tagName, 
specFamilyMap, specTagMaps)
+               locator = append(locator, partition.TagLocator{FamilyOffset: 
familyIdx, TagOffset: tagIdx})
+       }
+       return &specLocator{tagLocators: locator}
+}
+
+func buildSpecMaps[T tagFamilySpec](specFamilies []T) (map[string]int, 
map[string]map[string]int) {
+       specFamilyMap := make(map[string]int)
+       specTagMaps := make(map[string]map[string]int)
+       for i, specFamily := range specFamilies {
+               specFamilyMap[specFamily.GetName()] = i
+               tagMap := make(map[string]int)

Review Comment:
   The `tagMap` should be initialized with a capacity hint for better 
performance: `make(map[string]int, len(specFamily.GetTagNames()))`.
   ```suggestion
                tagMap := make(map[string]int, len(specFamily.GetTagNames()))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to