mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-11-10 03:01:14 +03:00
Simplify timer removal
This commit is contained in:
parent
dcec926590
commit
457aab7c41
@ -41,7 +41,7 @@ type Loop struct {
|
||||
keep_going bool
|
||||
death_signal unix.Signal
|
||||
exit_code int
|
||||
timers []*timer
|
||||
timers, timers_temp []*timer
|
||||
timer_id_counter, write_msg_id_counter IdType
|
||||
wakeup_channel chan byte
|
||||
pending_writes []*write_msg
|
||||
@ -72,7 +72,7 @@ type Loop struct {
|
||||
}
|
||||
|
||||
func New() (*Loop, error) {
|
||||
l := Loop{controlling_term: nil}
|
||||
l := Loop{controlling_term: nil, timers_temp: make([]*timer, 4)}
|
||||
l.terminal_options.alternate_screen = true
|
||||
l.escape_code_parser.HandleCSI = l.handle_csi
|
||||
l.escape_code_parser.HandleOSC = l.handle_osc
|
||||
|
@ -9,8 +9,9 @@ import (
|
||||
|
||||
func (self *Loop) dispatch_timers(now time.Time) error {
|
||||
updated := false
|
||||
remove := make(map[IdType]bool, 0)
|
||||
for _, t := range self.timers {
|
||||
self.timers_temp = self.timers_temp[:0]
|
||||
self.timers_temp = append(self.timers_temp, self.timers...)
|
||||
for i, t := range self.timers_temp {
|
||||
if now.After(t.deadline) {
|
||||
err := t.callback(t.id)
|
||||
if err != nil {
|
||||
@ -20,19 +21,10 @@ func (self *Loop) dispatch_timers(now time.Time) error {
|
||||
t.update_deadline(now)
|
||||
updated = true
|
||||
} else {
|
||||
remove[t.id] = true
|
||||
self.timers = append(self.timers[:i], self.timers[i+1:]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(remove) > 0 {
|
||||
timers := make([]*timer, len(self.timers)-len(remove))
|
||||
for _, t := range self.timers {
|
||||
if !remove[t.id] {
|
||||
timers = append(timers, t)
|
||||
}
|
||||
}
|
||||
self.timers = timers
|
||||
}
|
||||
if updated {
|
||||
self.sort_timers()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user