parser/html/nsHtml5ArrayCopy.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /*
michael@0 2 * Copyright (c) 2008 Mozilla Foundation
michael@0 3 *
michael@0 4 * Permission is hereby granted, free of charge, to any person obtaining a
michael@0 5 * copy of this software and associated documentation files (the "Software"),
michael@0 6 * to deal in the Software without restriction, including without limitation
michael@0 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
michael@0 8 * and/or sell copies of the Software, and to permit persons to whom the
michael@0 9 * Software is furnished to do so, subject to the following conditions:
michael@0 10 *
michael@0 11 * The above copyright notice and this permission notice shall be included in
michael@0 12 * all copies or substantial portions of the Software.
michael@0 13 *
michael@0 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
michael@0 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
michael@0 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
michael@0 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
michael@0 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
michael@0 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
michael@0 20 * DEALINGS IN THE SOFTWARE.
michael@0 21 */
michael@0 22
michael@0 23 #ifndef nsHtml5ArrayCopy_h
michael@0 24 #define nsHtml5ArrayCopy_h
michael@0 25
michael@0 26
michael@0 27 class nsString;
michael@0 28 class nsHtml5StackNode;
michael@0 29 class nsHtml5AttributeName;
michael@0 30
michael@0 31 // Unfortunately, these don't work as template functions because the arguments
michael@0 32 // would need coercion from a template class, which complicates things.
michael@0 33 class nsHtml5ArrayCopy {
michael@0 34 public:
michael@0 35
michael@0 36 static inline void
michael@0 37 arraycopy(char16_t* source, int32_t sourceOffset, char16_t* target, int32_t targetOffset, int32_t length)
michael@0 38 {
michael@0 39 memcpy(&(target[targetOffset]), &(source[sourceOffset]), length * sizeof(char16_t));
michael@0 40 }
michael@0 41
michael@0 42 static inline void
michael@0 43 arraycopy(char16_t* source, char16_t* target, int32_t length)
michael@0 44 {
michael@0 45 memcpy(target, source, length * sizeof(char16_t));
michael@0 46 }
michael@0 47
michael@0 48 static inline void
michael@0 49 arraycopy(int32_t* source, int32_t* target, int32_t length)
michael@0 50 {
michael@0 51 memcpy(target, source, length * sizeof(int32_t));
michael@0 52 }
michael@0 53
michael@0 54 static inline void
michael@0 55 arraycopy(nsString** source, nsString** target, int32_t length)
michael@0 56 {
michael@0 57 memcpy(target, source, length * sizeof(nsString*));
michael@0 58 }
michael@0 59
michael@0 60 static inline void
michael@0 61 arraycopy(nsHtml5AttributeName** source, nsHtml5AttributeName** target, int32_t length)
michael@0 62 {
michael@0 63 memcpy(target, source, length * sizeof(nsHtml5AttributeName*));
michael@0 64 }
michael@0 65
michael@0 66 static inline void
michael@0 67 arraycopy(nsHtml5StackNode** source, nsHtml5StackNode** target, int32_t length)
michael@0 68 {
michael@0 69 memcpy(target, source, length * sizeof(nsHtml5StackNode*));
michael@0 70 }
michael@0 71
michael@0 72 static inline void
michael@0 73 arraycopy(nsHtml5StackNode** arr, int32_t sourceOffset, int32_t targetOffset, int32_t length)
michael@0 74 {
michael@0 75 memmove(&(arr[targetOffset]), &(arr[sourceOffset]), length * sizeof(nsHtml5StackNode*));
michael@0 76 }
michael@0 77 };
michael@0 78 #endif // nsHtml5ArrayCopy_h

mercurial