summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-10 07:18:16 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-10 07:18:16 +0000
commit2f8d3bdc21b37f0d6881b817c8fd9c5b4b351cd4 (patch)
treeeb88114284c1e7a35677815487d122a68fdf9f57 /util.c
parent3493ea5c7acfeaf187873d4986181a5fda446aa3 (diff)
* array.c (rb_ary_modify): should copy the internal buffer if the
modifying buffer is shared. * array.c (ary_make_shared): make an internal buffer of an array to be shared. * array.c (rb_ary_shift): avoid sliding an internal buffer by using shared buffer. * array.c (rb_ary_subseq): avoid copying the buffer. * parse.y (gettable): should freeze __LINE__ string. * io.c (rb_io_puts): old behavoir restored. rationale: a) if you want to call to_s for arrays, you can just call print a, "\n". b) to_s wastes memory if array (and sum of its contents) is huge. c) now any object that has to_ary is treated as an array, using rb_check_convert_type(). * hash.c (rb_hash_initialize): now accepts a block to calculate the default value. [new] * hash.c (rb_hash_aref): call "default" method to get the value corrensponding to the non existing key. * hash.c (rb_hash_default): get the default value based on the block given to 'new'. Now it takes an optinal "key" argument. "default" became the method to get the value for non existing key. Users may override "default" method to change the hash behavior. * hash.c (rb_hash_set_default): clear the flag if a block is given to 'new' * object.c (Init_Object): undef Data.allocate, left Data.new. * ext/curses/curses.c (window_scrollok): use RTEST(). * ext/curses/curses.c (window_idlok): ditto. * ext/curses/curses.c (window_keypad): ditto. * ext/curses/curses.c (window_idlok): idlok() may return void on some platforms; so don't use return value. * ext/curses/curses.c (window_scrollok): ditto for consistency. * ext/curses/curses.c: replace FIX2INT() by typechecking NUM2INT(). * parse.y (str_extend): should not process immature #$x and #@x interpolation, e.g #@#@ etc. * enum.c (enum_sort_by): sort_by does not have to be stable always. * enum.c (enum_sort_by): call qsort directly to gain performance. * util.c (ruby_qsort): ruby_qsort(qs6) is now native thread safe. * error.c (rb_sys_fail): it must be a bug if it's called when errno == 0. * regex.c (WC2MBC1ST): should not pass through > 0x80 number in UTF-8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/util.c b/util.c
index bec54f4237..26a35ed398 100644
--- a/util.c
+++ b/util.c
@@ -384,31 +384,25 @@ __crt0_glob_function(char *path)
/* mm.c */
-static int mmkind, mmsize, high, low;
-
#define A ((int*)a)
#define B ((int*)b)
#define C ((int*)c)
#define D ((int*)d)
-static void mmprepare(base, size) void *base; int size;
-{
-#ifdef DEBUG
- if (sizeof(int) != 4) die("sizeof(int) != 4");
- if (size <= 0) die("mmsize <= 0");
-#endif
+#define mmprepare(base, size) do {\
+ if (((long)base & (0x3)) == 0)\
+ if (size >= 16) mmkind = 1;\
+ else mmkind = 0;\
+ else mmkind = -1;\
+ high = (size & (~0xf));\
+ low = (size & 0x0c);\
+} while (0)\
- if (((long)base & (4-1)) == 0 && ((long)base & (4-1)) == 0)
- if (size >= 16) mmkind = 1;
- else mmkind = 0;
- else mmkind = -1;
-
- mmsize = size;
- high = (size & (-16));
- low = (size & 0x0c);
-}
+#define mmarg mmkind, size, high, low
-static void mmswap(a, b) register char *a, *b;
+static void mmswap_(a, b, mmarg)
+ register char *a, *b;
+ int mmarg;
{
register int s;
if (a == b) return;
@@ -427,12 +421,15 @@ static void mmswap(a, b) register char *a, *b;
if (low == 12) {s = A[2]; A[2] = B[2]; B[2] = s;}}}
}
else {
- register char *t = a + mmsize;
+ register char *t = a + size;
do {s = *a; *a++ = *b; *b++ = s;} while (a < t);
}
}
+#define mmswap(a,b) mmswap_((a),(b),mmarg)
-static void mmrot3(a, b, c) register char *a, *b, *c;
+static void mmrot3_(a, b, c, mmarg)
+ register char *a, *b, *c;
+ int mmarg;
{
register int s;
if (mmkind >= 0) {
@@ -450,10 +447,11 @@ static void mmrot3(a, b, c) register char *a, *b, *c;
if (low == 12) {s = A[2]; A[2] = B[2]; B[2] = C[2]; C[2] = s;}}}
}
else {
- register char *t = a + mmsize;
+ register char *t = a + size;
do {s = *a; *a++ = *b; *b++ = *c; *c++ = s;} while (a < t);
}
}
+#define mmrot3(a,b,c) mmrot3_((a),(b),(c),mmarg)
/* qs6.c */
/*****************************************************/
@@ -472,14 +470,19 @@ typedef struct { char *LL, *RR; } stack_node; /* Stack structure for L,l,R,r */
((*cmp)(b,c)<0 ? b : ((*cmp)(a,c)<0 ? c : a)) : \
((*cmp)(b,c)>0 ? b : ((*cmp)(a,c)<0 ? a : c)))
-void ruby_qsort (base, nel, size, cmp) void* base; int nel; int size; int (*cmp)();
+void ruby_qsort (base, nel, size, cmp)
+ void* base;
+ const int nel;
+ const int size;
+ int (*cmp)();
{
register char *l, *r, *m; /* l,r:left,right group m:median point */
register int t, eq_l, eq_r; /* eq_l: all items in left group are equal to S */
char *L = base; /* left end of curren region */
- char *R = (char*)base + size*(nel-1); /* right end of current region */
- int chklim = 63; /* threshold of ordering element check */
- stack_node stack[32], *top = stack; /* 32 is enough for 32bit CPU */
+ char *R = (char*)base + size*(nel-1); /* right end of current region */
+ int chklim = 63; /* threshold of ordering element check */
+ stack_node stack[32], *top = stack; /* 32 is enough for 32bit CPU */
+ int mmkind, high, low;
if (nel <= 1) return; /* need not to sort */
mmprepare(base, size);
@@ -491,7 +494,9 @@ void ruby_qsort (base, nel, size, cmp) void* base; int nel; int size; int (*cmp)
for (;;) {
start:
- if (L + size == R) {if ((*cmp)(L,R) > 0) mmswap(L,R); goto nxt;}/* 2 elements */
+ if (L + size == R) { /* 2 elements */
+ if ((*cmp)(L,R) > 0) mmswap(L,R); goto nxt;
+ }
l = L; r = R;
t = (r - l + size) / size; /* number of elements */
@@ -559,7 +564,7 @@ void ruby_qsort (base, nel, size, cmp) void* base; int nel; int size; int (*cmp)
if ((t = (*cmp)(m,r)) < 0) {goto loopA;} /*5-5-7*/
if (t > 0) {mmswap(l,r); goto loopB;} /*5-5-3*/
- /* deteming splitting type in case 5-5-5 */ /*5-5-5*/
+ /* determining splitting type in case 5-5-5 */ /*5-5-5*/
for (;;) {
if ((l += size) == r) goto nxt; /*5-5-5*/
if (l == m) continue;