summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2013-06-16 16:19:30 +0000
committerGabriel Scherer <gabriel.scherer@gmail.com>2013-06-16 16:19:30 +0000
commit54a131a2629d14ca6a0bb51d8e3b1ed4bb573bfe (patch)
treee888b996b7c8e0efe8504be2ccce6e4aec99adb6
parentb23b2e0bde35ffb980ba6346ac2c65fcb4929745 (diff)
PR#4079: Queue.copy is now tail-recursive (patch from "Cristophe" on the bugtracker)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13784 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--Changes1
-rw-r--r--stdlib/queue.ml13
2 files changed, 8 insertions, 6 deletions
diff --git a/Changes b/Changes
index 932a3263b..5b8c32cea 100644
--- a/Changes
+++ b/Changes
@@ -56,6 +56,7 @@ Runtime system:
Bug fixes:
- PR#3679: Warning display problems
- PR#3963: Graphics.wait_next_event in Win32 hangs if window closed
+- PR#4079: Queue.copy is now tail-recursive
- PR#4762: ?? is not used at all, but registered as a lexer token
- PR#4887: input_char after close_in crashes ocaml (msvc runtime)
- PR#4994: ocaml-mode doesn't work with xemacs21
diff --git a/stdlib/queue.ml b/stdlib/queue.ml
index 6d82d2593..fb920d8c9 100644
--- a/stdlib/queue.ml
+++ b/stdlib/queue.ml
@@ -107,14 +107,15 @@ let copy q =
next = tail'
} in
- let rec copy cell =
- if cell == tail then tail'
- else {
+ let rec copy prev cell =
+ if cell != tail
+ then let res = {
content = cell.content;
- next = copy cell.next
- } in
+ next = tail'
+ } in prev.next <- res;
+ copy res cell.next in
- tail'.next <- copy tail.next;
+ copy tail' tail.next;
{
length = q.length;
tail = tail'