diff options
author | Gabriel Scherer <gabriel.scherer@gmail.com> | 2013-06-16 16:19:30 +0000 |
---|---|---|
committer | Gabriel Scherer <gabriel.scherer@gmail.com> | 2013-06-16 16:19:30 +0000 |
commit | 54a131a2629d14ca6a0bb51d8e3b1ed4bb573bfe (patch) | |
tree | e888b996b7c8e0efe8504be2ccce6e4aec99adb6 /stdlib/queue.ml | |
parent | b23b2e0bde35ffb980ba6346ac2c65fcb4929745 (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
Diffstat (limited to 'stdlib/queue.ml')
-rw-r--r-- | stdlib/queue.ml | 13 |
1 files changed, 7 insertions, 6 deletions
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' |