diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-01-14 07:45:19 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-01-14 07:45:19 +0000 |
| commit | 8f5c55e48c3e30c0c26886903cf4a16d2836f4ed (patch) | |
| tree | b36848da9832cfd527b06835c0affd2a78a1689d /parse.y | |
| parent | 9d3dd935f6ff481958857df9a28444c19e93b92d (diff) | |
| download | ruby-8f5c55e48c3e30c0c26886903cf4a16d2836f4ed.tar.gz ruby-8f5c55e48c3e30c0c26886903cf4a16d2836f4ed.tar.xz ruby-8f5c55e48c3e30c0c26886903cf4a16d2836f4ed.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@3340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
| -rw-r--r-- | parse.y | 32 |
1 files changed, 20 insertions, 12 deletions
@@ -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: |
