| // Copyright 2022 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package slog |
| |
| // concat returns a new slice with the elements of s1 followed |
| // by those of s2. The slice has no additional capacity. |
| func concat[T any](s1, s2 []T) []T { |
| s := make([]T, len(s1)+len(s2)) |
| copy(s, s1) |
| copy(s[len(s1):], s2) |
| return s |
| } |
| |
| // Cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding. |
| // Copied from log/log.go. |
| func itoa(buf *[]byte, i int, wid int) { |
| // Assemble decimal in reverse order. |
| var b [20]byte |
| bp := len(b) - 1 |
| for i >= 10 || wid > 1 { |
| wid-- |
| q := i / 10 |
| b[bp] = byte('0' + i - q*10) |
| bp-- |
| i = q |
| } |
| // i < 10 |
| b[bp] = byte('0' + i) |
| *buf = append(*buf, b[bp:]...) |
| } |