summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-14 07:45:19 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-14 07:45:19 +0000
commit6e1f15fc8b7e62360d32bc6ca47b1309d25b7766 (patch)
treeb36848da9832cfd527b06835c0affd2a78a1689d /parse.y
parent8c900ac9bfa9566462d96d1f870dff87df81da8c (diff)
* parse.y (list_append): avoid O(n) search using node->nd_next->nd_end.
* parse.y (list_append): ditto. * eval.c (rb_eval): NODE_ARRY nd_end adoption. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y32
1 files changed, 20 insertions, 12 deletions
diff --git a/parse.y b/parse.y
index 67da743135..4ceb6c3a2a 100644
--- a/parse.y
+++ b/parse.y
@@ -4501,14 +4501,16 @@ list_append(list, item)
NODE *last;
if (list == 0) return NEW_LIST(item);
-
- last = list;
- while (last->nd_next) {
- last = last->nd_next;
+ if (list->nd_next) {
+ last = list->nd_next->nd_end;
+ }
+ else {
+ last = list;
}
- last->nd_next = NEW_LIST(item);
list->nd_alen += 1;
+ last->nd_next = NEW_LIST(item);
+ list->nd_next->nd_end = last->nd_next;
return list;
}
@@ -4519,13 +4521,21 @@ list_concat(head, tail)
{
NODE *last;
- last = head;
- while (last->nd_next) {
- last = last->nd_next;
+ if (head->nd_next) {
+ last = head->nd_next->nd_end;
+ }
+ else {
+ last = head;
}
- last->nd_next = tail;
head->nd_alen += tail->nd_alen;
+ last->nd_next = tail;
+ if (tail->nd_next) {
+ head->nd_next->nd_end = tail->nd_next->nd_end;
+ }
+ else {
+ head->nd_next->nd_end = tail;
+ }
return head;
}
@@ -4543,9 +4553,7 @@ literal_concat(head, tail)
htype = nd_type(head);
if (htype == NODE_EVSTR) {
NODE *node = NEW_DSTR(rb_str_new(0, 0));
- node->nd_next = NEW_LIST(head);
- node->nd_alen += 1;
- head = node;
+ head = list_append(node, head);
}
switch (nd_type(tail)) {
case NODE_STR: