mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-08-06 22:04:11 +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.
|
// Subhyphae returns slice of subhyphae.
|
||||||
func (h *Hypha) Subhyphae() []*Hypha {
|
func (h *Hypha) Subhyphae() []*Hypha {
|
||||||
hyphae := []*Hypha{}
|
var hyphae []*Hypha
|
||||||
for subh := range YieldExistingHyphae() {
|
for subh := range YieldExistingHyphae() {
|
||||||
if strings.HasPrefix(subh.Name, h.Name+"/") {
|
if strings.HasPrefix(subh.Name, h.Name+"/") {
|
||||||
hyphae = append(hyphae, subh)
|
hyphae = append(hyphae, subh)
|
||||||
|
@ -82,7 +82,7 @@ func SaveUserDatabase() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dumpUserCredentials() error {
|
func dumpUserCredentials() error {
|
||||||
userList := []*User{}
|
var userList []*User
|
||||||
|
|
||||||
// TODO: lock the map during saving to prevent corruption
|
// TODO: lock the map during saving to prevent corruption
|
||||||
for u := range YieldUsers() {
|
for u := range YieldUsers() {
|
||||||
@ -119,5 +119,8 @@ func dumpTokens() {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
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.
|
// ListUsersWithGroup returns a slice with users of desired group.
|
||||||
func ListUsersWithGroup(group string) []string {
|
func ListUsersWithGroup(group string) []string {
|
||||||
filtered := []string{}
|
var filtered []string
|
||||||
for u := range YieldUsers() {
|
for u := range YieldUsers() {
|
||||||
if u.Group == group {
|
if u.Group == group {
|
||||||
filtered = append(filtered, u.Name)
|
filtered = append(filtered, u.Name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user