mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-04 18:19:54 +00:00
Use zero-allocation approach for empty slices
For further reading checkout https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices
This commit is contained in:
parent
b2789f923f
commit
94706e8468
@ -79,7 +79,7 @@ func PathographicSort(src chan string) <-chan string {
|
||||
|
||||
// Subhyphae returns slice of subhyphae.
|
||||
func (h *Hypha) Subhyphae() []*Hypha {
|
||||
hyphae := []*Hypha{}
|
||||
var hyphae []*Hypha
|
||||
for subh := range YieldExistingHyphae() {
|
||||
if strings.HasPrefix(subh.Name, h.Name+"/") {
|
||||
hyphae = append(hyphae, subh)
|
||||
|
@ -82,7 +82,7 @@ func SaveUserDatabase() error {
|
||||
}
|
||||
|
||||
func dumpUserCredentials() error {
|
||||
userList := []*User{}
|
||||
var userList []*User
|
||||
|
||||
// TODO: lock the map during saving to prevent corruption
|
||||
for u := range YieldUsers() {
|
||||
@ -119,5 +119,8 @@ func dumpTokens() {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
os.WriteFile(files.TokensJSON(), blob, 0666)
|
||||
err = os.WriteFile(files.TokensJSON(), blob, 0666)
|
||||
if err != nil {
|
||||
log.Println("an error occurred in dumpTokens function:", err)
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ func YieldUsers() chan *User {
|
||||
|
||||
// ListUsersWithGroup returns a slice with users of desired group.
|
||||
func ListUsersWithGroup(group string) []string {
|
||||
filtered := []string{}
|
||||
var filtered []string
|
||||
for u := range YieldUsers() {
|
||||
if u.Group == group {
|
||||
filtered = append(filtered, u.Name)
|
||||
|
Loading…
Reference in New Issue
Block a user