[Mono-dev] Endianess in resource reading

Neale Ferguson neale at sinenomine.net
Fri Apr 10 00:55:34 UTC 2015


I have tracked down the failure of the Windows.Forms tests and have found
it is due to the values that are extracted from the resource data. In
AllocateStringForNameIndex()
(external/referencesource/mscorlib/system/resources/resourcereader.cs) we
convert a char array to a string on the assumption the endianness is
correct. As s390x is big endian there needs to be a swap. This fragment of
code does the job but is it optimal?

                    if (!BitConverter.IsLittleEndian) {
                        byte* bytePtr = (byte*) charPtr;
                        var dest = new byte[byteLen];
                        for (int i = 0; i < byteLen; i += 2) {
                                dest[i] = *(bytePtr+i+1);
                                dest[i+1] = *(bytePtr+i);
                        }
                        fixed(byte *pDest = dest) {
                            s = new String((char *)pDest, 0, byteLen/2);
                        }
                    } else {
                        s = new String(charPtr, 0, byteLen/2);
                    }



Neale



More information about the Mono-devel-list mailing list