🚀 optimize code

This commit is contained in:
ValKmjolnir 2022-08-08 22:10:51 +08:00
parent 7ddb8593ad
commit 0493e18d0e
4 changed files with 7 additions and 5 deletions

View File

@ -53,7 +53,7 @@ void logo()
<<" / \\/ / _` / __|/ _` | |\n" <<" / \\/ / _` / __|/ _` | |\n"
<<" / /\\ / (_| \\__ \\ (_| | |\n" <<" / /\\ / (_| \\__ \\ (_| | |\n"
<<" \\_\\ \\/ \\__,_|___/\\__,_|_|\n" <<" \\_\\ \\/ \\__,_|___/\\__,_|_|\n"
<<"nasal ver : "<<__nasver<<"\n" <<"nasal ver : "<<__nasver<<" ("<<__DATE__<<")\n"
<<"c++ std : "<<__cplusplus<<"\n" <<"c++ std : "<<__cplusplus<<"\n"
<<"thanks to : https://github.com/andyross/nasal\n" <<"thanks to : https://github.com/andyross/nasal\n"
<<"code repo : https://github.com/ValKmjolnir/Nasal-Interpreter\n" <<"code repo : https://github.com/ValKmjolnir/Nasal-Interpreter\n"

View File

@ -133,8 +133,7 @@ nas_ref builtin_split(nas_ref* local,nasal_gc& gc)
gc.temp=nil; gc.temp=nil;
return res; return res;
} }
usize last=0; usize last=0,pos=s.find(deli,0);
usize pos=s.find(deli,last);
while(pos!=string::npos) while(pos!=string::npos)
{ {
if(pos>last) if(pos>last)

View File

@ -34,8 +34,7 @@ nasal_import::nasal_import(nasal_err& e):lib_loaded(false),nerr(e){
char sep=':'; char sep=':';
#endif #endif
string PATH=getenv("PATH"); string PATH=getenv("PATH");
usize last=0; usize last=0,pos=PATH.find(sep,0);
usize pos=PATH.find(sep,last);
while(pos!=string::npos) while(pos!=string::npos)
{ {
string dirpath=PATH.substr(last,pos-last); string dirpath=PATH.substr(last,pos-last);

View File

@ -5,6 +5,8 @@ var file={
SEEK_CUR:io.SEEK_CUR, SEEK_CUR:io.SEEK_CUR,
SEEK_END:io.SEEK_END, SEEK_END:io.SEEK_END,
new: func(filename,mode="r"){ new: func(filename,mode="r"){
if(!io.exists(filename))
return nil;
var fd=io.open(filename,mode); var fd=io.open(filename,mode);
return { return {
close: func(){io.close(fd);}, close: func(){io.close(fd);},
@ -24,6 +26,8 @@ var file={
}; };
var find_all_files=func(path){ var find_all_files=func(path){
if(!io.exists(path))
return [];
var dd=unix.opendir(path); var dd=unix.opendir(path);
var res=[]; var res=[];
while(var n=unix.readdir(dd)) while(var n=unix.readdir(dd))