parser/html/nsHtml5ArrayCopy.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/html/nsHtml5ArrayCopy.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +/*
     1.5 + * Copyright (c) 2008 Mozilla Foundation
     1.6 + *
     1.7 + * Permission is hereby granted, free of charge, to any person obtaining a
     1.8 + * copy of this software and associated documentation files (the "Software"),
     1.9 + * to deal in the Software without restriction, including without limitation
    1.10 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    1.11 + * and/or sell copies of the Software, and to permit persons to whom the
    1.12 + * Software is furnished to do so, subject to the following conditions:
    1.13 + *
    1.14 + * The above copyright notice and this permission notice shall be included in
    1.15 + * all copies or substantial portions of the Software.
    1.16 + *
    1.17 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1.18 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1.19 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    1.20 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    1.21 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    1.22 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    1.23 + * DEALINGS IN THE SOFTWARE.
    1.24 + */
    1.25 +
    1.26 +#ifndef nsHtml5ArrayCopy_h
    1.27 +#define nsHtml5ArrayCopy_h
    1.28 +
    1.29 +
    1.30 +class nsString;
    1.31 +class nsHtml5StackNode;
    1.32 +class nsHtml5AttributeName;
    1.33 +
    1.34 +// Unfortunately, these don't work as template functions because the arguments
    1.35 +// would need coercion from a template class, which complicates things.
    1.36 +class nsHtml5ArrayCopy {
    1.37 +  public:
    1.38 +
    1.39 +    static inline void
    1.40 +    arraycopy(char16_t* source, int32_t sourceOffset, char16_t* target, int32_t targetOffset, int32_t length)
    1.41 +    {
    1.42 +      memcpy(&(target[targetOffset]), &(source[sourceOffset]), length * sizeof(char16_t));
    1.43 +    }
    1.44 +
    1.45 +    static inline void
    1.46 +    arraycopy(char16_t* source, char16_t* target, int32_t length)
    1.47 +    {
    1.48 +      memcpy(target, source, length * sizeof(char16_t));
    1.49 +    }
    1.50 +
    1.51 +    static inline void
    1.52 +    arraycopy(int32_t* source, int32_t* target, int32_t length)
    1.53 +    {
    1.54 +      memcpy(target, source, length * sizeof(int32_t));
    1.55 +    }
    1.56 +
    1.57 +    static inline void
    1.58 +    arraycopy(nsString** source, nsString** target, int32_t length)
    1.59 +    {
    1.60 +      memcpy(target, source, length * sizeof(nsString*));
    1.61 +    }
    1.62 +
    1.63 +    static inline void
    1.64 +    arraycopy(nsHtml5AttributeName** source, nsHtml5AttributeName** target, int32_t length)
    1.65 +    {
    1.66 +      memcpy(target, source, length * sizeof(nsHtml5AttributeName*));
    1.67 +    }
    1.68 +
    1.69 +    static inline void
    1.70 +    arraycopy(nsHtml5StackNode** source, nsHtml5StackNode** target, int32_t length)
    1.71 +    {
    1.72 +      memcpy(target, source, length * sizeof(nsHtml5StackNode*));
    1.73 +    }
    1.74 +
    1.75 +    static inline void
    1.76 +    arraycopy(nsHtml5StackNode** arr, int32_t sourceOffset, int32_t targetOffset, int32_t length)
    1.77 +    {
    1.78 +      memmove(&(arr[targetOffset]), &(arr[sourceOffset]), length * sizeof(nsHtml5StackNode*));
    1.79 +    }
    1.80 +};
    1.81 +#endif // nsHtml5ArrayCopy_h

mercurial