Skip to content

Commit

Permalink
use an empty string cache
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Dec 25, 2017
1 parent 1dc5a40 commit d819443
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion iolib.go
Expand Up @@ -372,7 +372,7 @@ func fileReadAux(L *LState, file *lFile, idx int) int {
var buf []byte
buf, err = ioutil.ReadAll(file.reader)
if err == io.EOF {
L.Push(LString(""))
L.Push(emptyLString)
goto normalreturn
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion loadlib.go
Expand Up @@ -63,7 +63,7 @@ func OpenPackage(L *LState) int {
L.SetField(L.Get(RegistryIndex), "_LOADED", loaded)

L.SetField(packagemod, "path", LString(loGetPath(LuaPath, LuaPathDefault)))
L.SetField(packagemod, "cpath", LString(""))
L.SetField(packagemod, "cpath", emptyLString)

L.Push(packagemod)
return 1
Expand Down
6 changes: 4 additions & 2 deletions stringlib.go
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/yuin/gopher-lua/pm"
)

const emptyLString LString = LString("")

func OpenString(L *LState) int {
var mod *LTable
//_, ok := L.G.builtinMts[int(LTString)]
Expand Down Expand Up @@ -391,7 +393,7 @@ func strRep(L *LState) int {
str := L.CheckString(1)
n := L.CheckInt(2)
if n < 0 {
L.Push(LString(""))
L.Push(emptyLString)
} else {
L.Push(LString(strings.Repeat(str, n)))
}
Expand All @@ -415,7 +417,7 @@ func strSub(L *LState) int {
end := luaIndex2StringIndex(str, L.OptInt(3, -1), false)
l := len(str)
if start >= l || end < start {
L.Push(LString(""))
L.Push(emptyLString)
} else {
L.Push(LString(str[start:end]))
}
Expand Down
4 changes: 2 additions & 2 deletions tablelib.go
Expand Up @@ -56,14 +56,14 @@ func tableConcat(L *LState) int {
j := L.OptInt(4, tbl.Len())
if L.GetTop() == 3 {
if i > tbl.Len() || i < 1 {
L.Push(LString(""))
L.Push(emptyLString)
return 1
}
}
i = intMax(intMin(i, tbl.Len()), 1)
j = intMin(intMin(j, tbl.Len()), tbl.Len())
if i > j {
L.Push(LString(""))
L.Push(emptyLString)
return 1
}
//TODO should flushing?
Expand Down

0 comments on commit d819443

Please sign in to comment.