pike.git/
src/
builtin_functions.c
Branch:
Tag:
Non-build tags
All tags
No tags
2000-04-22
2000-04-22 02:23:25 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>
ff8d73228e01de1ee4b654beedcc63671f5598b8 (
30
lines) (+
17
/-
13
)
[
Show
|
Annotate
]
Branch:
7.9
uniq optimized
Rev: src/builtin_functions.c:1.267
5:
\*/ /**/ #include "global.h"
-
RCSID("$Id: builtin_functions.c,v 1.
266
2000/04/
19
22:
26
:
00
grubba
Exp $");
+
RCSID("$Id: builtin_functions.c,v 1.
267
2000/04/
22
02
:
23
:
25
hubbe
Exp $");
#include "interpret.h" #include "svalue.h" #include "pike_macros.h"
4554:
} /* uniqify an array while at the same time keeping the order intact */
-
void f_uniq_array(INT32 args)
{
+
void f_uniq_array(INT32 args)
+
{
struct array *a, *b;
-
struct svalue s;
+
struct mapping *m; struct svalue one;
-
int i, j=0;
+
int i, j=0
,size=0
;
+
get_all_args("uniq", args, "%a", &a);
-
m = allocate_mapping(a->size);
+
push_mapping(
m = allocate_mapping(a->size)
)
;
+
push_array(b = allocate_array(a->size));
+
one.type = T_INT; one.u.integer = 1;
-
b = allocate_array(a->size);
+
for(i =0; i< a->size; i++) {
-
s
=
ITEM(a)
[i]
;
-
if(
!low
_
mapping_lookup
(m
,
&s
)
)
{
-
mapping
_
insert
(m
, &s, &one
);
-
assign_svalue(
&(
ITEM(b)
[
j++
])
,
&s
);
+
mapping_insert(m,
ITEM(a)
+i, &one)
;
+
if(
m
_
sizeof
(m
)
!= size
)
+
{
+
size=m
_
sizeof
(m);
+
assign_svalue
_no_free
(ITEM(b)
+
j++,
ITEM(a
)
+i)
;
} }
-
resize_array(b, j);
-
free_mapping(m);
-
pop_n_elems(args);
+
sp--; /* keep the ref to 'b' */
+
b=
resize_array(b, j);
+
pop_n_elems(args
-1
);
/* pop args and the mapping */
push_array(b); }