Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
e09f4c02
Commit
e09f4c02
authored
28 years ago
by
Fredrik Hübinette (Hubbe)
Browse files
Options
Downloads
Patches
Plain Diff
various optimizations
Rev: lib/simulate.lpc:1.16
parent
7eb15e65
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/simulate.lpc
+26
-46
26 additions, 46 deletions
lib/simulate.lpc
with
26 additions
and
46 deletions
lib/simulate.lpc
+
26
−
46
View file @
e09f4c02
...
...
@@ -43,50 +43,29 @@ mixed *map_array(mixed *arr, mixed fun, mixed ... args)
if(intp(fun))
return arr(@args);
ret=allocate(sizeof(arr));
if(stringp(fun))
return column(arr, fun)(@args);
if(functionp(fun))
{
for(e=0;e<sizeof(arr);e++)
ret[e]=arr[e][fun](@args);
}
else if(functionp(fun))
{
ret=allocate(sizeof(arr));
for(e=0;e<sizeof(arr);e++)
ret[e]=fun(arr[e],@args);
}else{
error("Bad argument 2 to map_array().\n");
}
return ret;
}
error("Bad argument 2 to map_array().\n");
}
mixed *filter_array(mixed *arr, mixed fun, mixed ... args)
{
int e,d;
mixed *ret;
ret=allocate(sizeof(arr));
if(stringp(fun))
{
ret=map_array(arr,fun,@args);
for(e=0;e<sizeof(arr);e++)
if(
arr[e][fun](@args)
)
if(
ret[e]
)
ret[d++]=arr[e];
}
else if(functionp(fun))
{
for(e=0;e<sizeof(arr);e++)
if(fun(arr[e],@args))
ret[d++]=arr[e];
}
else if(intp(fun))
{
for(e=0;e<sizeof(arr);e++)
if(arr[e](@args))
ret[d++]=arr[e];
}
else
{
error("Bad argument 2 to filter_array().\n");
}
return ret[0..d-1];
}
...
...
@@ -126,13 +105,13 @@ varargs int exec(string file,string ... foo)
{
string path;
if(search(file,"/"))
return exece(combine_path(getcwd(),file),foo);
return exece(combine_path(getcwd(),file),foo
,getenv()
);
path=getenv("PATH");
foreach(path/":",path)
if(file_stat(path=combine_path(path,file)))
return exece(path, foo);
return exece(path, foo
,getenv()
);
return 69;
}
...
...
@@ -197,8 +176,8 @@ void system(string s)
current_file=current_mode=0;
p=file::pipe();
if(!p) error("System() failed.\n");
p->set_close_on_exec(0);
if(!p) error("System failed.\n");
if(pid=fork())
{
destruct(p);
...
...
@@ -229,15 +208,11 @@ varargs string code_value(mixed s,int a)
mixed *sum_arrays(function foo, mixed * ... args)
{
mixed
*tmp,
*ret;
mixed *ret;
int e,d;
tmp=allocate(sizeof(args));
ret=allocate(sizeof(args[0]));
for(e=0;e<sizeof(args[0]);e++)
{
for(d=0;d<sizeof(args);d++) tmp[d]=args[d][e];
ret[e]=foo(@tmp);
}
ret[e]=foo(@ column(args, e));
return ret;
}
...
...
@@ -281,10 +256,17 @@ varargs mixed *sort_array(array foo,function cmp, mixed ... args)
return foo;
}
if(cmp == `<)
{
foo+=({});
sort(foo);
reverse(foo);
return foo;
}
length=sizeof(foo);
foo+=({});
// perror(sprintf("DEBUG: %O\n",foo));
bar=allocate(length);
for(len=1;len<length;len*=2)
...
...
@@ -297,8 +279,6 @@ varargs mixed *sort_array(array foo,function cmp, mixed ... args)
fooend=barp;
barend=barp+len;
if(barend > length) barend=length;
if(barend <= barp)
error("OOPS");
while(1)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment