e32tools/elf2e32/source/deflatecompress.cpp
changeset 666 76dc8e3e7f2e
parent 590 360bd6b35136
equal deleted inserted replaced
665:2068325a5906 666:76dc8e3e7f2e
    28 // hashing
    28 // hashing
    29 const TUint KDeflateHashMultiplier=0xAC4B9B19u;
    29 const TUint KDeflateHashMultiplier=0xAC4B9B19u;
    30 const TInt KDeflateHashShift=24;
    30 const TInt KDeflateHashShift=24;
    31 
    31 
    32 #define COMPILE_TIME_ASSERT(e)	\
    32 #define COMPILE_TIME_ASSERT(e)	\
    33  	switch (0)					\
    33 	switch (0)					\
    34  	{							\
    34 	{							\
    35  	case 0:						\
    35 	case 0:						\
    36  	case e:						\
    36 	case e:						\
    37  		;						\
    37 		;						\
    38  	}
    38 	}
    39 
       
    40 
    39 
    41 /**
    40 /**
    42 Class HDeflateHash
    41 Class HDeflateHash
    43 @internalComponent
    42 @internalComponent
    44 @released
    43 @released
   134 */
   133 */
   135 inline HDeflateHash* HDeflateHash::NewLC(TInt aLinks)
   134 inline HDeflateHash* HDeflateHash::NewLC(TInt aLinks)
   136 {
   135 {
   137 #if __GNUC__ >= 4
   136 #if __GNUC__ >= 4
   138  	// Try to detect if the class' layout has changed.
   137  	// Try to detect if the class' layout has changed.
   139  	COMPILE_TIME_ASSERT( sizeof(HDeflateHash) == 1028 );
   138 	COMPILE_TIME_ASSERT( sizeof(HDeflateHash) == 1028 );
   140  	COMPILE_TIME_ASSERT( sizeof(TOffset) == 2 );
   139 	COMPILE_TIME_ASSERT( sizeof(TOffset) == 2 );
   141  	COMPILE_TIME_ASSERT( offsetof(HDeflateHash, iHash) < offsetof(HDeflateHash, iOffset) );
   140 	COMPILE_TIME_ASSERT( offsetof(HDeflateHash, iHash) < offsetof(HDeflateHash, iOffset) );
   142  
   141  
   143  	// Compute the size of the class, including rounding it up to a multiple of 4
   142  	// Compute the size of the class, including rounding it up to a multiple of 4
   144  	// bytes.
   143  	// bytes.
   145  
   144 	unsigned n = sizeof(TInt) * 256 + sizeof(TOffset) * Min(aLinks, KDeflateMaxDistance);
   146  	unsigned n = sizeof(TInt) * 256 + sizeof(TOffset) * Min(aLinks, KDeflateMaxDistance);
   145 	while (n & 0x1f)
   147  
   146 	{
   148  	while (n & 0x1f)
   147 		n++;	
   149  	{
   148 	}
   150  		n++;	
       
   151  	}
       
   152  	// Allocate the raw memory ...
   149  	// Allocate the raw memory ...
   153  	void* p = ::operator new(n);
   150 	void* p = ::operator new(n);
   154  	// ... And create the object in that memory.
   151  	// ... And create the object in that memory.
   155  	return new(p) HDeflateHash;
   152 	return new(p) HDeflateHash;
   156 #else
   153 #else
   157    	return new(new char[_FOFF(HDeflateHash,iOffset[Min(aLinks,KDeflateMaxDistance)])]) HDeflateHash;
   154    	return new(new char[_FOFF(HDeflateHash,iOffset[Min(aLinks,KDeflateMaxDistance)])]) HDeflateHash;
   158 #endif
   155 #endif
   159    }
   156    }
   160 
   157