Skip to content

Commit

Permalink
perf: Improve rule.Kind (#1919)
Browse files Browse the repository at this point in the history
**What type of PR is this?**
Perf improvement

**What package or component does this PR mostly affect?**
gazelle core

**What does this PR do? Why is it needed?**
This is a simple change that is a ~2%+ improvement on our medium-sized
repo. (The 2% is easily measurable; there is also decreased GC pressure
which is spread out)

**Which issues(s) does this PR fix?**

Fixes #

**Other notes for review**
  • Loading branch information
dzbarsky authored Sep 14, 2024
1 parent 0890963 commit ba1cae3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ func (l *Load) sync() {
// Rule represents a rule statement within a build file.
type Rule struct {
stmt
kind bzl.Expr
kind string
args []bzl.Expr
attrs map[string]attrValue
private map[string]interface{}
Expand All @@ -748,7 +748,7 @@ func NewRule(kind, name string) *Rule {

r := &Rule{
stmt: stmt{expr: call},
kind: kindIdent,
kind: kind,
attrs: map[string]attrValue{},
private: map[string]interface{}{},
sortedAttrs: []string{"deps", "srcs"},
Expand Down Expand Up @@ -850,7 +850,7 @@ func ruleFromExpr(index int, expr bzl.Expr) *Rule {
expr: call,
comments: commentsFromExpr(expr),
},
kind: kind,
kind: bzl.FormatString(kind),
args: args,
attrs: attrs,
private: map[string]interface{}{},
Expand All @@ -866,12 +866,12 @@ func (r *Rule) ShouldKeep() bool {

// Kind returns the kind of rule this is (for example, "go_library").
func (r *Rule) Kind() string {
return bzl.FormatString(r.kind)
return r.kind
}

// SetKind changes the kind of rule this is.
func (r *Rule) SetKind(kind string) {
r.kind = &bzl.Ident{Name: kind}
r.kind = kind
r.updated = true
}

Expand Down

0 comments on commit ba1cae3

Please sign in to comment.