From 3637d636de96d71570b41f9db7e636e69de1be7f Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Tue, 5 Nov 2013 13:02:54 +1300 Subject: [PATCH] b=856850 add PodMove r=Waldo --HG-- extra : transplant_source : %27%04%F0%2B%96%1B0%A7%DB%81D%26%81%A0u%C9j%3E%A2%B0 --- mfbt/PodOperations.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mfbt/PodOperations.h b/mfbt/PodOperations.h index bec89fa9285..1a92811e5d4 100644 --- a/mfbt/PodOperations.h +++ b/mfbt/PodOperations.h @@ -133,6 +133,21 @@ PodArrayCopy(T (&dst)[N], const T (&src)[N]) PodCopy(dst, src, N); } +/** + * Copy the memory for |nelem| T elements from |src| to |dst|. If the two + * memory ranges overlap, then the effect is as if the |nelem| elements are + * first copied from |src| to a temporary array, and then from the temporary + * array to |dst|. + */ +template +MOZ_ALWAYS_INLINE static void +PodMove(T* dst, const T* src, size_t nelem) +{ + MOZ_ASSERT(nelem <= SIZE_MAX / sizeof(T), + "trying to move an impossible number of elements"); + memmove(dst, src, nelem * sizeof(T)); +} + /** * Determine whether the |len| elements at |one| are memory-identical to the * |len| elements at |two|.