]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/udataswp.c
ICU-531.30.tar.gz
[apple/icu.git] / icuSources / common / udataswp.c
index cacf716610eb7cfff136926f5b0021120555fc4b..06fe85bc463c0defcf4ee78d1c4995ff89acd6cb 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2003, International Business Machines
+*   Copyright (C) 2003-2014, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -123,6 +123,55 @@ uprv_copyArray32(const UDataSwapper *ds,
     return length;
 }
 
+static int32_t U_CALLCONV
+uprv_swapArray64(const UDataSwapper *ds,
+                 const void *inData, int32_t length, void *outData,
+                 UErrorCode *pErrorCode) {
+    const uint64_t *p;
+    uint64_t *q;
+    int32_t count;
+
+    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+        return 0;
+    }
+    if(ds==NULL || inData==NULL || length<0 || (length&7)!=0 || outData==NULL) {
+        *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+        return 0;
+    }
+
+    /* setup and swapping */
+    p=(const uint64_t *)inData;
+    q=(uint64_t *)outData;
+    count=length/8;
+    while(count>0) {
+        uint64_t x=*p++;
+        x=(x<<56)|((x&0xff00)<<40)|((x&0xff0000)<<24)|((x&0xff000000)<<8)|
+            ((x>>8)&0xff000000)|((x>>24)&0xff0000)|((x>>40)&0xff00)|(x>>56);
+        *q++=x;
+        --count;
+    }
+
+    return length;
+}
+
+static int32_t U_CALLCONV
+uprv_copyArray64(const UDataSwapper *ds,
+                 const void *inData, int32_t length, void *outData,
+                 UErrorCode *pErrorCode) {
+    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+        return 0;
+    }
+    if(ds==NULL || inData==NULL || length<0 || (length&7)!=0 || outData==NULL) {
+        *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+        return 0;
+    }
+
+    if(length>0 && inData!=outData) {
+        uprv_memcpy(outData, inData, length);
+    }
+    return length;
+}
+
 static uint16_t U_CALLCONV
 uprv_readSwapUInt16(uint16_t x) {
     return (uint16_t)((x<<8)|(x>>8));
@@ -344,8 +393,15 @@ udata_openSwapper(UBool inIsBigEndian, uint8_t inCharset,
 
     swapper->compareInvChars= outCharset==U_ASCII_FAMILY ? uprv_compareInvAscii : uprv_compareInvEbcdic;
 
-    swapper->swapArray16= inIsBigEndian==outIsBigEndian ? uprv_copyArray16 : uprv_swapArray16;
-    swapper->swapArray32= inIsBigEndian==outIsBigEndian ? uprv_copyArray32 : uprv_swapArray32;
+    if(inIsBigEndian==outIsBigEndian) {
+        swapper->swapArray16=uprv_copyArray16;
+        swapper->swapArray32=uprv_copyArray32;
+        swapper->swapArray64=uprv_copyArray64;
+    } else {
+        swapper->swapArray16=uprv_swapArray16;
+        swapper->swapArray32=uprv_swapArray32;
+        swapper->swapArray64=uprv_swapArray64;
+    }
 
     if(inCharset==U_ASCII_FAMILY) {
         swapper->swapInvChars= outCharset==U_ASCII_FAMILY ? uprv_copyAscii : uprv_ebcdicFromAscii;