From 54a131a2629d14ca6a0bb51d8e3b1ed4bb573bfe Mon Sep 17 00:00:00 2001 From: Gabriel Scherer Date: Sun, 16 Jun 2013 16:19:30 +0000 Subject: [PATCH] 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 --- Changes | 1 + stdlib/queue.ml | 13 +++++++------ 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'