summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-11-09 09:11:52 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-11-09 09:11:52 +0000
commitee5ab9cc136baf18756abc6bd5d136a0231f973e (patch)
treeabdc351cbffd7b67f63f41ea08f544819af0a28b /array.c
parentdc8da69e7cbc54f020ef1182fd28e57bbaa40fc3 (diff)
1.1c7
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/array.c b/array.c
index 6150d862dd..10d554ba2c 100644
--- a/array.c
+++ b/array.c
@@ -370,32 +370,29 @@ beg_len(range, begp, lenp, len)
int len;
{
int beg, end;
+ int b, e;
if (!range_beg_end(range, &beg, &end)) return FALSE;
-
- if ((beg > 0 && end > 0 || beg < 0 && end < 0) && beg > end) {
- IndexError("end smaller than beg [%d..%d]", beg, end);
- }
+ b = beg; e = end;
if (beg < 0) {
beg = len + beg;
if (beg < 0) beg = 0;
}
+ if (end < 0) {
+ end = len + end;
+ if (end < 0) end = -1;
+ }
+ if (beg > end) {
+ IndexError("end smaller than beg [%d..%d]", b, e);
+ }
+
*begp = beg;
if (beg > len) {
*lenp = 0;
}
else {
- if (end < 0) {
- end = len + end;
- if (end < 0) end = -1;
- }
- if (beg > end) {
- *lenp = 0;
- }
- else {
- *lenp = end - beg +1;
- }
+ *lenp = end - beg +1;
}
return TRUE;
}