mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Avoid unnecessary byte/string conversions (#69001)
Avoid unnecessary byte/string conversion We can use alternative functions/methods to avoid unnecessary byte/string conversion calls. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
515270f5fd
commit
7f7b03d794
@ -238,10 +238,10 @@ func generateConflictUsersFile(r *ConflictResolver) (*os.File, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := tmpFile.Write([]byte(getDocumentationForFile())); err != nil {
|
if _, err := tmpFile.WriteString(getDocumentationForFile()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := tmpFile.Write([]byte(r.ToStringPresentation())); err != nil {
|
if _, err := tmpFile.WriteString(r.ToStringPresentation()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return tmpFile, nil
|
return tmpFile, nil
|
||||||
@ -280,7 +280,7 @@ func getValidConflictUsers(r *ConflictResolver, b []byte) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
entryRow := matchingExpression.Match([]byte(row))
|
entryRow := matchingExpression.MatchString(row)
|
||||||
// not an entry row -> is a conflict block row
|
// not an entry row -> is a conflict block row
|
||||||
if !entryRow {
|
if !entryRow {
|
||||||
// check for malformed row
|
// check for malformed row
|
||||||
|
@ -97,7 +97,7 @@ func (ss *sqlStore) Update(ctx context.Context, cmd folder.UpdateFolderCommand)
|
|||||||
}
|
}
|
||||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||||
sql := strings.Builder{}
|
sql := strings.Builder{}
|
||||||
sql.Write([]byte("UPDATE folder SET "))
|
sql.WriteString("UPDATE folder SET ")
|
||||||
columnsToUpdate := []string{"updated = ?"}
|
columnsToUpdate := []string{"updated = ?"}
|
||||||
args := []interface{}{updated}
|
args := []interface{}{updated}
|
||||||
if cmd.NewDescription != nil {
|
if cmd.NewDescription != nil {
|
||||||
@ -129,8 +129,8 @@ func (ss *sqlStore) Update(ctx context.Context, cmd folder.UpdateFolderCommand)
|
|||||||
return folder.ErrBadRequest.Errorf("no columns to update")
|
return folder.ErrBadRequest.Errorf("no columns to update")
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.Write([]byte(strings.Join(columnsToUpdate, ", ")))
|
sql.WriteString(strings.Join(columnsToUpdate, ", "))
|
||||||
sql.Write([]byte(" WHERE uid = ? AND org_id = ?"))
|
sql.WriteString(" WHERE uid = ? AND org_id = ?")
|
||||||
args = append(args, cmd.UID, cmd.OrgID)
|
args = append(args, cmd.UID, cmd.OrgID)
|
||||||
|
|
||||||
args = append([]interface{}{sql.String()}, args...)
|
args = append([]interface{}{sql.String()}, args...)
|
||||||
@ -244,10 +244,10 @@ func (ss *sqlStore) GetChildren(ctx context.Context, q folder.GetChildrenQuery)
|
|||||||
sql := strings.Builder{}
|
sql := strings.Builder{}
|
||||||
args := make([]interface{}, 0, 2)
|
args := make([]interface{}, 0, 2)
|
||||||
if q.UID == "" {
|
if q.UID == "" {
|
||||||
sql.Write([]byte("SELECT * FROM folder WHERE parent_uid IS NULL AND org_id=? ORDER BY title ASC"))
|
sql.WriteString("SELECT * FROM folder WHERE parent_uid IS NULL AND org_id=? ORDER BY title ASC")
|
||||||
args = append(args, q.OrgID)
|
args = append(args, q.OrgID)
|
||||||
} else {
|
} else {
|
||||||
sql.Write([]byte("SELECT * FROM folder WHERE parent_uid=? AND org_id=? ORDER BY title ASC"))
|
sql.WriteString("SELECT * FROM folder WHERE parent_uid=? AND org_id=? ORDER BY title ASC")
|
||||||
args = append(args, q.UID, q.OrgID)
|
args = append(args, q.UID, q.OrgID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ func (ss *sqlStore) GetChildren(ctx context.Context, q folder.GetChildrenQuery)
|
|||||||
if q.Page > 0 {
|
if q.Page > 0 {
|
||||||
offset = q.Limit * (q.Page - 1)
|
offset = q.Limit * (q.Page - 1)
|
||||||
}
|
}
|
||||||
sql.Write([]byte(ss.db.GetDialect().LimitOffset(q.Limit, offset)))
|
sql.WriteString(ss.db.GetDialect().LimitOffset(q.Limit, offset))
|
||||||
}
|
}
|
||||||
err := sess.SQL(sql.String(), args...).Find(&folders)
|
err := sess.SQL(sql.String(), args...).Find(&folders)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -160,7 +160,7 @@ func (m *kqlMacroEngine) ReplaceAllStringSubmatchFunc(re *regexp.Regexp, str str
|
|||||||
result := ""
|
result := ""
|
||||||
lastIndex := 0
|
lastIndex := 0
|
||||||
|
|
||||||
for _, v := range re.FindAllSubmatchIndex([]byte(str), -1) {
|
for _, v := range re.FindAllStringSubmatchIndex(str, -1) {
|
||||||
groups := []string{}
|
groups := []string{}
|
||||||
for i := 0; i < len(v); i += 2 {
|
for i := 0; i < len(v); i += 2 {
|
||||||
if v[i] < 0 {
|
if v[i] < 0 {
|
||||||
|
@ -60,7 +60,7 @@ func (query *Query) renderTags() []string {
|
|||||||
|
|
||||||
// If the operator is missing we fall back to sensible defaults
|
// If the operator is missing we fall back to sensible defaults
|
||||||
if tag.Operator == "" {
|
if tag.Operator == "" {
|
||||||
if regexpOperatorPattern.Match([]byte(tag.Value)) {
|
if regexpOperatorPattern.MatchString(tag.Value) {
|
||||||
tag.Operator = "=~"
|
tag.Operator = "=~"
|
||||||
} else {
|
} else {
|
||||||
tag.Operator = "="
|
tag.Operator = "="
|
||||||
@ -124,7 +124,7 @@ func (query *Query) renderMeasurement() string {
|
|||||||
|
|
||||||
measurement := query.Measurement
|
measurement := query.Measurement
|
||||||
|
|
||||||
if !regexpMeasurementPattern.Match([]byte(measurement)) {
|
if !regexpMeasurementPattern.MatchString(measurement) {
|
||||||
measurement = fmt.Sprintf(`"%s"`, measurement)
|
measurement = fmt.Sprintf(`"%s"`, measurement)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1019,7 +1019,7 @@ func (m *SQLMacroEngineBase) ReplaceAllStringSubmatchFunc(re *regexp.Regexp, str
|
|||||||
result := ""
|
result := ""
|
||||||
lastIndex := 0
|
lastIndex := 0
|
||||||
|
|
||||||
for _, v := range re.FindAllSubmatchIndex([]byte(str), -1) {
|
for _, v := range re.FindAllStringSubmatchIndex(str, -1) {
|
||||||
groups := []string{}
|
groups := []string{}
|
||||||
for i := 0; i < len(v); i += 2 {
|
for i := 0; i < len(v); i += 2 {
|
||||||
groups = append(groups, str[v[i]:v[i+1]])
|
groups = append(groups, str[v[i]:v[i+1]])
|
||||||
|
Loading…
Reference in New Issue
Block a user