Mercurial > projects > dwt-win
diff dwt/internal/image/PngChunk.d @ 80:1801ddeb8f32
removed static ctors
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 06 Feb 2008 12:09:44 +0100 |
parents | 9a64a7781bab |
children | ab60f3309436 |
line wrap: on
line diff
--- a/dwt/internal/image/PngChunk.d Wed Feb 06 11:08:01 2008 +0100 +++ b/dwt/internal/image/PngChunk.d Wed Feb 06 12:09:44 2008 +0100 @@ -52,19 +52,28 @@ static const byte[] TYPE_IEND = cast(byte[])"IEND";//{(byte) 'I', (byte) 'E', (byte) 'N', (byte) 'D'}; static const byte[] TYPE_tRNS = cast(byte[])"tRNS";//{(byte) 't', (byte) 'R', (byte) 'N', (byte) 'S'}; - static const int[] CRC_TABLE; - //public static void static_this() { - static this() { - CRC_TABLE = new int[256]; - for (int i = 0; i < 256; i++) { - CRC_TABLE[i] = i; - for (int j = 0; j < 8; j++) { - if ((CRC_TABLE[i] & 0x1) is 0) { - CRC_TABLE[i] = (CRC_TABLE[i] >> 1) & 0x7FFFFFFF; - } else { - CRC_TABLE[i] = 0xEDB88320 ^ ((CRC_TABLE[i] >> 1) & 0x7FFFFFFF); + private static /+const+/ int[] CRC_TABLE; + private static bool static_this_completed = false; + private static void static_this() { + if( static_this_completed ){ + return; + } + synchronized { + if( static_this_completed ){ + return; + } + CRC_TABLE = new int[256]; + for (int i = 0; i < 256; i++) { + CRC_TABLE[i] = i; + for (int j = 0; j < 8; j++) { + if ((CRC_TABLE[i] & 0x1) is 0) { + CRC_TABLE[i] = (CRC_TABLE[i] >> 1) & 0x7FFFFFFF; + } else { + CRC_TABLE[i] = 0xEDB88320 ^ ((CRC_TABLE[i] >> 1) & 0x7FFFFFFF); + } } } + static_this_completed = true; } } @@ -75,6 +84,7 @@ * given. */ this(byte[] reference) { + static_this(); setReference(reference); if (reference.length < LENGTH_OFFSET + LENGTH_FIELD_LENGTH) DWT.error(DWT.ERROR_INVALID_IMAGE); length = getInt32(LENGTH_OFFSET);