better memory efficiency, bug fixes

This commit is contained in:
diamondburned 2021-01-03 01:36:43 -08:00
parent 5151d47427
commit bcd2de2e49
5 changed files with 24 additions and 16 deletions

2
go.mod
View File

@ -2,7 +2,7 @@ module github.com/diamondburned/cchat-gtk
go 1.14
replace github.com/gotk3/gotk3 => github.com/diamondburned/gotk3 v0.0.0-20201230071527-a77c32eb3876
replace github.com/gotk3/gotk3 => github.com/diamondburned/gotk3 v0.0.0-20210103063209-2bfa1d9dd9a6
// replace github.com/diamondburned/cchat-discord => ../cchat-discord
// replace github.com/diamondburned/gotk3-tcmalloc => ../../gotk3-tcmalloc

2
go.sum
View File

@ -106,6 +106,8 @@ github.com/diamondburned/gotk3 v0.0.0-20201229104206-9bea3709a385 h1:nmlMCeEWmT6
github.com/diamondburned/gotk3 v0.0.0-20201229104206-9bea3709a385/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
github.com/diamondburned/gotk3 v0.0.0-20201230071527-a77c32eb3876 h1:8Hacuan9iBgoYyjJFYOP/TgghY4QWxT70qoV5NFGKmc=
github.com/diamondburned/gotk3 v0.0.0-20201230071527-a77c32eb3876/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
github.com/diamondburned/gotk3 v0.0.0-20210103063209-2bfa1d9dd9a6 h1:dJwNpjlgUP3YTPll5LvqyhpuaBPjITUuDes7Wq8HrTM=
github.com/diamondburned/gotk3 v0.0.0-20210103063209-2bfa1d9dd9a6/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
github.com/diamondburned/gspell v0.0.0-20200830182722-77e5d27d6894 h1:QgI21deaQbCUMnxKkQQUXzQolnAe1dMIXAWwqAyOp2g=
github.com/diamondburned/gspell v0.0.0-20200830182722-77e5d27d6894/go.mod h1:IoyMxPKSJOMoP0BiBuFwf2RDMeA4Uqx0HPKN5BzqTtA=
github.com/diamondburned/gspell v0.0.0-20201229064336-e43698fd5828 h1:Lm1F+GwrDdAaaMzrR7AYl4GGd/T+FE2OgOz25QWwsIg=

View File

@ -13,7 +13,7 @@ import (
// BacklogLimit is the maximum number of messages to store in the container at
// once.
const BacklogLimit = 35
const BacklogLimit = 50
type MessageRow interface {
message.Container

View File

@ -1,6 +1,7 @@
package container
import (
"log"
"time"
"github.com/diamondburned/cchat"
@ -153,8 +154,11 @@ func (c *ListStore) around(aroundID cchat.ID) (before, after *messageRow) {
// LatestMessageFrom returns the latest message with the given user ID. This is
// used for the input prompt.
func (c *ListStore) LatestMessageFrom(userID string) (msgID string, ok bool) {
log.Println("LatestMessageFrom called")
// FindMessage already looks from the latest messages.
var msg = c.FindMessage(func(msg MessageRow) bool {
log.Println("Author:", msg.AuthorName())
return msg.AuthorID() == userID
})
@ -198,14 +202,17 @@ func (c *ListStore) findMessage(presend bool, fn func(*messageRow) bool) (*messa
id := primitives.GetName(v.(primitives.Namer))
gridMsg := c.message(id, "")
// Ignore sending messages.
if (presend || gridMsg.presend == nil) && fn(gridMsg) {
r = gridMsg
return true
// If gridMsg is actually nil, then we have bigger issues.
if gridMsg != nil {
// Ignore sending messages.
if (presend || gridMsg.presend == nil) && fn(gridMsg) {
r = gridMsg
return true
}
}
i--
return i == 0
return false
})
// Preserve old behavior.
@ -405,10 +412,12 @@ func (c *ListStore) DeleteEarliest(n int) {
// Since container/list nils out the next element, we can't just call Next
// after deleting, so we have to call Next manually before Removing.
primitives.ForeachChildBackwards(c.ListBox, func(v interface{}) (stop bool) {
primitives.ForeachChild(c.ListBox, func(v interface{}) (stop bool) {
id := primitives.GetName(v.(primitives.Namer))
gridMsg := c.message(id, "")
log.Println("Deleting overflowed message ID from", gridMsg.AuthorName())
if id := gridMsg.ID(); id != "" {
delete(c.messages, idKey(id))
}

View File

@ -31,7 +31,7 @@ func RemoveChildren(w Container) {
}
children := w.GetChildren()
children.Foreach(func(child interface{}) { child.(destroyer).Destroy() })
children.Foreach(func(child interface{}) { w.Remove(child.(gtk.IWidget)) })
children.Free()
}
@ -47,6 +47,9 @@ func NthChild(w Container, n int) interface{} {
children := w.GetChildren()
defer children.Free()
if n == 0 {
return children.Data()
}
return children.NthData(uint(n))
}
@ -69,13 +72,7 @@ func ForeachChildBackwards(w Container, fn func(interface{}) (stop bool)) {
children := w.GetChildren()
defer children.Free()
// Seek to last.
var last = children
for last != nil {
last = last.Next()
}
for v := last; v != nil; v = v.Previous() {
for v := children.Last(); v != nil; v = v.Previous() {
if fn(v.Data()) {
break
}