perf: reorder struct fields

this apparently saves in memory usage. not sure
how this is going to impact normal usage, but...
cleanup
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
FuncSig string
FuncName string
Doc []string
}
// feel free to clean this up
@ -28,10 +28,9 @@ func main() {
fset := token.NewFileSet()
os.Mkdir("docs", 0777)
os.Mkdir("emmyLuaDocs", 0777)
dirs := []string{"./"}
filepath.Walk("golibs/", func (path string, info os.FileInfo, err error) error {
filepath.Walk("golibs/", func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
return nil
}
@ -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:]
@ -88,19 +91,21 @@ func main() {
funcdoc = append(funcdoc, d)
}
}
dps := DocPiece{
Doc: funcdoc,
FuncSig: funcsig,
Doc: funcdoc,
FuncSig: funcsig,
FuncName: strings.TrimPrefix(t.Name, prefix[mod]),
}
docs[mod] = append(docs[mod], dps)
emmyDocs[mod] = append(emmyDocs[mod], em)
}
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 + " > ")
@ -147,9 +154,11 @@ func main() {
f.WriteString("\n")
}
}
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,21 +19,21 @@ 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")
var errNotFound = errors.New("not found")
var runnerMode rt.Value = rt.StringValue("hybrid")
type execError struct{
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
@ -19,18 +20,18 @@ const (
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
type Listener struct {
caller func(...interface{})
luaCaller *rt.Closure
typ listenerType
once bool
}
type Bait struct{
Loader packagelib.Loader
type Bait struct {
recoverer Recoverer
handlers map[string][]*Listener
handlers map[string][]*Listener
rtm *rt.Runtime
Loader packagelib.Loader
}
// New creates a new Bait instance.
@ -316,8 +317,10 @@ 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 }
luaHandlers.Set(rt.IntValue(luaHandlers.Len() + 1), rt.FunctionValue(handler.luaCaller))
if handler.typ != luaListener {
continue
}
luaHandlers.Set(rt.IntValue(luaHandlers.Len()+1), rt.FunctionValue(handler.luaCaller))
}
if luaHandlers.Len() == 0 {

View File

@ -10,7 +10,7 @@ import (
rt "github.com/arnodel/golua/runtime"
)
type luaHistory struct {}
type luaHistory struct{}
func (h *luaHistory) Write(line string) (int, error) {
histWrite := hshMod.Get(rt.StringValue("history")).AsTable().Get(rt.StringValue("add"))
@ -54,8 +54,8 @@ func (h *luaHistory) Dump() interface{} {
}
type fileHistory struct {
f *os.File
items []string
f *os.File
}
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{
type timer struct {
ticker *time.Ticker
ud *rt.UserData
channel chan struct{}
fun *rt.Closure
th *timerHandler
dur time.Duration
id int
typ timerType
running bool
dur time.Duration
fun *rt.Closure
th *timerHandler
ticker *time.Ticker
ud *rt.UserData
channel chan struct{}
}
func (t *timer) start() error {
@ -56,7 +57,7 @@ func (t *timer) start() error {
}
}
}()
return nil
}
@ -69,7 +70,7 @@ func (t *timer) stop() error {
t.running = false
t.th.running--
t.th.wg.Done()
return nil
}
@ -87,7 +88,7 @@ func timerStart(thr *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err != nil {
return nil, err
}
return c.Next(), nil
}