perf: reorder struct fields

this apparently saves in memory usage. not sure
how this is going to impact normal usage, but...
TorchedSammy 2022-11-27 21:30:54 -04:00
parent bd4e0df7b3
commit 63359cdb1e
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
6 changed files with 68 additions and 57 deletions

View File

@ -2,13 +2,13 @@ package main
import (
"fmt"
"path/filepath"
"go/ast"
"go/doc"
"go/parser"
"go/token"
"strings"
"os"
"path/filepath"
"strings"
)
type EmmyPiece struct {
@ -17,9 +17,9 @@ type EmmyPiece struct {
Params []string // we only need to know param name to put in function
}
type DocPiece struct {
Doc []string
FuncSig string
FuncName string
Doc []string
}
// feel free to clean this up
@ -29,7 +29,6 @@ func main() {
os.Mkdir("docs", 0777)
os.Mkdir("emmyLuaDocs", 0777)
dirs := []string{"./"}
filepath.Walk("golibs/", func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
@ -65,8 +64,12 @@ func main() {
p := doc.New(f, "./", doc.AllDecls)
for _, t := range p.Funcs {
mod := l
if strings.HasPrefix(t.Name, "hl") { mod = "hilbish" }
if !strings.HasPrefix(t.Name, prefix[mod]) || t.Name == "Loader" { continue }
if strings.HasPrefix(t.Name, "hl") {
mod = "hilbish"
}
if !strings.HasPrefix(t.Name, prefix[mod]) || t.Name == "Loader" {
continue
}
parts := strings.Split(strings.TrimSpace(t.Doc), "\n")
funcsig := parts[0]
doc := parts[1:]
@ -100,7 +103,9 @@ func main() {
}
for _, t := range p.Types {
for _, m := range t.Methods {
if !strings.HasPrefix(m.Name, prefix[l]) || m.Name == "Loader" { continue }
if !strings.HasPrefix(m.Name, prefix[l]) || m.Name == "Loader" {
continue
}
parts := strings.Split(strings.TrimSpace(m.Doc), "\n")
funcsig := parts[0]
doc := parts[1:]
@ -135,7 +140,9 @@ func main() {
}
for mod, v := range docs {
if mod == "main" { continue }
if mod == "main" {
continue
}
f, _ := os.Create("docs/" + mod + ".txt")
for _, dps := range v {
f.WriteString(dps.FuncSig + " > ")
@ -149,7 +156,9 @@ func main() {
}
for mod, v := range emmyDocs {
if mod == "main" { continue }
if mod == "main" {
continue
}
f, _ := os.Create("emmyLuaDocs/" + mod + ".lua")
f.WriteString("--- @meta\n\nlocal " + mod + " = {}\n\n")
for _, em := range v {

View File

@ -4,10 +4,10 @@ import (
"bytes"
"context"
"errors"
"os/exec"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
@ -19,9 +19,9 @@ import (
rt "github.com/arnodel/golua/runtime"
"mvdan.cc/sh/v3/shell"
//"github.com/yuin/gopher-lua/parse"
"mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax"
"mvdan.cc/sh/v3/expand"
)
var errNotExec = errors.New("not executable")
@ -29,11 +29,11 @@ var errNotFound = errors.New("not found")
var runnerMode rt.Value = rt.StringValue("hybrid")
type execError struct {
err error
typ string
cmd string
code int
colon bool
err error
}
func (e execError) Error() string {

View File

@ -5,11 +5,12 @@ import (
"hilbish/util"
rt "github.com/arnodel/golua/runtime"
"github.com/arnodel/golua/lib/packagelib"
rt "github.com/arnodel/golua/runtime"
)
type listenerType int
const (
goListener listenerType = iota
luaListener
@ -20,17 +21,17 @@ type Recoverer func(event string, handler *Listener, err interface{})
// Listener is a struct that holds the handler for an event.
type Listener struct {
typ listenerType
once bool
caller func(...interface{})
luaCaller *rt.Closure
typ listenerType
once bool
}
type Bait struct {
Loader packagelib.Loader
recoverer Recoverer
handlers map[string][]*Listener
rtm *rt.Runtime
Loader packagelib.Loader
}
// New creates a new Bait instance.
@ -316,7 +317,9 @@ func (b *Bait) bhooks(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
luaHandlers := rt.NewTable()
for _, handler := range handlers {
if handler.typ != luaListener { continue }
if handler.typ != luaListener {
continue
}
luaHandlers.Set(rt.IntValue(luaHandlers.Len()+1), rt.FunctionValue(handler.luaCaller))
}

View File

@ -54,8 +54,8 @@ func (h *luaHistory) Dump() interface{} {
}
type fileHistory struct {
items []string
f *os.File
items []string
}
func newFileHistory(path string) *fileHistory {

30
job.go
View File

@ -19,22 +19,20 @@ var jobs *jobHandler
var jobMetaKey = rt.StringValue("hshjob")
type job struct {
cmd string
running bool
id int
pid int
exitCode int
once bool
args []string
// save path for a few reasons, one being security (lmao) while the other
// would just be so itll be the same binary command always (path changes)
path string
handle *exec.Cmd
cmdout io.Writer
cmderr io.Writer
stdout *bytes.Buffer
stderr *bytes.Buffer
cmdout io.Writer
ud *rt.UserData
stderr *bytes.Buffer
stdout *bytes.Buffer
handle *exec.Cmd
path string
cmd string
args []string
exitCode int
pid int
id int
once bool
running bool
}
func (j *job) start() error {
@ -204,9 +202,9 @@ func luaBackgroundJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
type jobHandler struct {
jobs map[int]*job
latestID int
foreground bool // if job currently in the foreground
mu *sync.RWMutex
latestID int
foreground bool
}
func newJobHandler() *jobHandler {

View File

@ -10,21 +10,22 @@ import (
)
type timerType int64
const (
timerInterval timerType = iota
timerTimeout
)
type timer struct {
id int
typ timerType
running bool
dur time.Duration
fun *rt.Closure
th *timerHandler
ticker *time.Ticker
ud *rt.UserData
channel chan struct{}
fun *rt.Closure
th *timerHandler
dur time.Duration
id int
typ timerType
running bool
}
func (t *timer) start() error {