From ac2f8c9ac66a15a9e1799da3e8436928aeada53e Mon Sep 17 00:00:00 2001 From: Chongyi Zheng Date: Mon, 28 Aug 2023 12:43:16 -0400 Subject: [PATCH] Reduce some allocations in type conversion (#26772) --- modules/log/event_writer_base.go | 2 +- services/packages/rpm/repository.go | 2 +- services/pull/pull.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/log/event_writer_base.go b/modules/log/event_writer_base.go index b8b13e4bc4..c327c48ca2 100644 --- a/modules/log/event_writer_base.go +++ b/modules/log/event_writer_base.go @@ -90,7 +90,7 @@ func (b *EventWriterBaseImpl) Run(ctx context.Context) { if exprRegexp != nil { fileLineCaller := fmt.Sprintf("%s:%d:%s", event.Origin.Filename, event.Origin.Line, event.Origin.Caller) - matched := exprRegexp.Match([]byte(fileLineCaller)) || exprRegexp.Match([]byte(event.Origin.MsgSimpleText)) + matched := exprRegexp.MatchString(fileLineCaller) || exprRegexp.MatchString(event.Origin.MsgSimpleText) if !matched { continue } diff --git a/services/packages/rpm/repository.go b/services/packages/rpm/repository.go index 774613509e..cfd70ec23e 100644 --- a/services/packages/rpm/repository.go +++ b/services/packages/rpm/repository.go @@ -232,7 +232,7 @@ func buildRepomd(pv *packages_model.PackageVersion, ownerID int64, data []*repoD } var buf bytes.Buffer - buf.Write([]byte(xml.Header)) + buf.WriteString(xml.Header) if err := xml.NewEncoder(&buf).Encode(&Repomd{ Xmlns: "http://linux.duke.edu/metadata/repo", XmlnsRpm: "http://linux.duke.edu/metadata/rpm", diff --git a/services/pull/pull.go b/services/pull/pull.go index 0b6194b143..d4352abafe 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -755,11 +755,11 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ } for _, author := range authors { - if _, err := stringBuilder.Write([]byte("Co-authored-by: ")); err != nil { + if _, err := stringBuilder.WriteString("Co-authored-by: "); err != nil { log.Error("Unable to write to string builder Error: %v", err) return "" } - if _, err := stringBuilder.Write([]byte(author)); err != nil { + if _, err := stringBuilder.WriteString(author); err != nil { log.Error("Unable to write to string builder Error: %v", err) return "" }