toolsandutils/e32tools/elf2e32/source/deflatecompress.cpp
branchGCC_SURGE
changeset 61 b376866b09e6
parent 0 83f4b4db085c
equal deleted inserted replaced
60:5a90ee674b42 61:b376866b09e6
    26 const TInt KDeflateMaxDistance=(1<<KDeflateDistanceMag);
    26 const TInt KDeflateMaxDistance=(1<<KDeflateDistanceMag);
    27 
    27 
    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 
       
    32 #define COMPILE_TIME_ASSERT(e)	\
       
    33 	switch (0)					\
       
    34 	{							\
       
    35 	case 0:						\
       
    36 	case e:						\
       
    37 		;						\
       
    38 	}
       
    39 
    31 
    40 /**
    32 /**
    41 Class HDeflateHash
    33 Class HDeflateHash
    42 @internalComponent
    34 @internalComponent
    43 @released
    35 @released
   131 @internalComponent
   123 @internalComponent
   132 @released
   124 @released
   133 */
   125 */
   134 inline HDeflateHash* HDeflateHash::NewLC(TInt aLinks)
   126 inline HDeflateHash* HDeflateHash::NewLC(TInt aLinks)
   135 {
   127 {
   136 #if __GNUC__ >= 4
   128 	//return new(HMem::Alloc(0,_FOFF(HDeflateHash,iOffset[Min(aLinks,KDeflateMaxDistance)]))) HDeflateHash;
   137 	// Try to detect if the class' layout has changed.
       
   138 	COMPILE_TIME_ASSERT( sizeof(HDeflateHash) == 1028 );
       
   139 	COMPILE_TIME_ASSERT( sizeof(TOffset) == 2 );
       
   140 	COMPILE_TIME_ASSERT( offsetof(HDeflateHash, iHash) < offsetof(HDeflateHash, iOffset) );
       
   141 
       
   142 	// Compute the size of the class, including rounding it up to a multiple of 4
       
   143 	// bytes.
       
   144 
       
   145 	unsigned n = sizeof(TInt) * 256 + sizeof(TOffset) * Min(aLinks, KDeflateMaxDistance);
       
   146 
       
   147 	while (n & 0x1f)
       
   148 	{
       
   149 		n++;	
       
   150 	}
       
   151 
       
   152 	// Allocate the raw memory ...
       
   153 	void* p = ::operator new(n);
       
   154 
       
   155 	// ... And create the object in that memory.
       
   156 	return new(p) HDeflateHash;
       
   157 #else
       
   158 	return new(new char[_FOFF(HDeflateHash,iOffset[Min(aLinks,KDeflateMaxDistance)])]) HDeflateHash;
   129 	return new(new char[_FOFF(HDeflateHash,iOffset[Min(aLinks,KDeflateMaxDistance)])]) HDeflateHash;
   159 #endif
       
   160 }
   130 }
   161 
   131 
   162 /**
   132 /**
   163 Hash function for HDeflateHash
   133 Hash function for HDeflateHash
   164 @param aPtr
   134 @param aPtr