[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]
Re: [XaraXtreme-dev] gcmaths.h lost?
- From: Martin Wuerthner <lists@xxxxxxxxxxxxxxx>
- Date: Wed, 22 Mar 2006 16:23:34 +0100
- Subject: Re: [XaraXtreme-dev] gcmaths.h lost?
In message <4421562C.2020002@xxxxxxxxxxx>
Alex Bligh <alex@xxxxxxxxxxx> wrote:
> Martin Wuerthner wrote:
>> Was the header file gcmaths.h forgotten when creating the LX sources?
>> It is referenced in gcache.cpp and should define the Hash() function.
>
> Looks like the function is in assembler and was never converted to C.
> It used to say:
>
> UINT32 Hash( UINT32 H )
> {
> __asm {
> [...]
> I'm sure you can put together a C implementation pretty trivially.
OK, can someone please check in these changes to gcache.h, gcache.cpp
and fntcache.h?
renamed GCache to CamCache to avoid conflict with GLib's GCache
added Hash function to gcache.cpp (converted from assembler)
Martin
Index: Kernel/gcache.h
===================================================================
--- Kernel/gcache.h (Revision 706)
+++ Kernel/gcache.h (Arbeitskopie)
@@ -163,15 +163,15 @@
************************************************************************************************/
-class GCache
+class CamCache
{
#ifdef _DEBUG
- friend ostream& operator << ( ostream& os, GCache& Cache ) ;
+ friend ostream& operator << ( ostream& os, CamCache& Cache ) ;
#endif
public:
- GCache( size_t Size = 0x40000, UINT32 Log2MaxEntries = 12 ) ;
- ~GCache() ;
+ CamCache( size_t Size = 0x40000, UINT32 Log2MaxEntries = 12 ) ;
+ ~CamCache() ;
BOOL Verify() ;
BOOL FindPath( UINT32 Handle, INT32* &Points, BYTE* &Types, UINT32 &Length ) ;
Index: Kernel/gcache.cpp
===================================================================
--- Kernel/gcache.cpp (Revision 706)
+++ Kernel/gcache.cpp (Arbeitskopie)
@@ -102,28 +102,36 @@
*/
#include "camtypes.h"
-#include <afxwin.h>
-#include <iostream.h>
-#include "gcmaths.h"
+//#include <afxwin.h>
+#include <iostream>
+//#include "gcmaths.h"
#include "gcache.h"
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
-GCache::GCache( size_t Size, UINT32 Log2MaxEntries )
+CamCache::CamCache( size_t Size, UINT32 Log2MaxEntries )
{
HashTableSize = 1<<Log2MaxEntries ;
HashTableMask = HashTableSize-1 ;
HashTable = NULL ;
CacheStart = NULL ;
- TRY {
- HashTable = new ( CacheBlock* [HashTableSize] ) ;
- CacheStart = (CacheBlock*) new BYTE[Size+2*FreeCacheBlockSize] ;
- } CATCH_ALL (e) {
- delete [] HashTable ; HashTable = NULL ;
- delete [] CacheStart ; CacheStart = NULL ;
+
+ HashTable = new ( CacheBlock* [HashTableSize] ) ;
+ CacheStart = (CacheBlock*) new BYTE[Size+2*FreeCacheBlockSize] ;
+
+ if (!HashTable || !CacheStart)
+ {
+ if (HashTable)
+ {
+ delete [] HashTable ; HashTable = NULL ;
+ }
+ if (CacheStart)
+ {
+ delete [] CacheStart ; CacheStart = NULL ;
+ }
return ;
- } END_CATCH_ALL ;
+ }
for ( size_t i=0 ; i<HashTableSize ; i++ )
HashTable[i] = NULL ;
CacheBlock *FreeBlock ;
@@ -143,16 +151,16 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
-// Verify should be used after creation of a GCache object to ensure that it was created OK.
+// Verify should be used after creation of a CamCache object to ensure that it was created OK.
//
-BOOL GCache::Verify()
+BOOL CamCache::Verify()
{
return HashTable && CacheStart ;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
-GCache::~GCache()
+CamCache::~CamCache()
{
delete [] HashTable ; HashTable = NULL ;
delete [] CacheStart ; CacheStart = NULL ;
@@ -161,7 +169,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
-BOOL GCache::FindPath( UINT32 Handle, INT32* &Points, BYTE* &Types, UINT32 &Length )
+BOOL CamCache::FindPath( UINT32 Handle, INT32* &Points, BYTE* &Types, UINT32 &Length )
{
INT32 *Object = (INT32*) FindEntry( Handle ) ;
if ( Object )
@@ -173,12 +181,13 @@
return Object!=NULL ;
}
-void GCache::AddPath( UINT32 Handle, INT32* Points, BYTE* Types, UINT32 Length )
+void CamCache::AddPath( UINT32 Handle, INT32* Points, BYTE* Types, UINT32 Length )
{
INT32 *DPtr = (INT32*) AddEntry( Handle,Length*9+4 ) ;
*DPtr++ = Length ;
INT32 *SPtr = Points ;
- for ( size_t i=0 ; i<2*Length ; i++ )
+ size_t i;
+ for ( i=0 ; i<2*Length ; i++ )
*DPtr++ = *SPtr++ ;
SPtr = (INT32*) Types ;
Length = (Length+3)>>2 ; /* Word length */
@@ -189,12 +198,15 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
-char* GCache::FindString( UINT32 Handle )
+PORTNOTE("other","not used - removed because AddString looks dodgy")
+#ifndef EXCLUDE_FROM_XARALX
+
+char* CamCache::FindString( UINT32 Handle )
{
return (char*) FindEntry( Handle ) ;
}
-void GCache::AddString( UINT32 Handle, char* String )
+void CamCache::AddString( UINT32 Handle, char* String )
{
size_t StringLength = cc_strlenBytes(String)+1 ; /* Byte length */
INT32 *SPtr = (INT32*) String ;
@@ -203,12 +215,23 @@
for ( size_t i=0 ; i<StringLength ; i++ )
*DPtr++ = *SPtr++ ;
}
+#endif
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
-void* GCache::FindEntry( UINT32 Handle )
+// converted from asm function in gcmaths
+UINT32 Hash(UINT32 val)
{
+ val ^= (val << 7) | (val >> 25);
+ val ^= (val << 11) | (val >> 21);
+ val ^= (val << 19) | (val >> 13);
+ val ^= (val << 16) | (val >> 16);
+ return val;
+}
+
+void* CamCache::FindEntry( UINT32 Handle )
+{
UINT32 HashIndex = Hash( Handle ) & HashTableMask ;
CacheBlock *Ptr = HashTable[HashIndex] ;
while ( Ptr )
@@ -237,7 +260,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
-void* GCache::AddEntry( UINT32 Handle, size_t ObjectSize )
+void* CamCache::AddEntry( UINT32 Handle, size_t ObjectSize )
{
UINT32 HashIndex = Hash( Handle ) & HashTableMask ;
CacheBlock *Ptr = HashTable[HashIndex] ;
@@ -324,7 +347,7 @@
#ifdef _DEBUG
-ostream& operator << ( ostream& os, GCache& Cache )
+ostream& operator << ( ostream& os, CamCache& Cache )
{
for ( size_t i=0 ; i<Cache.HashTableSize ; i++ )
{
@@ -349,7 +372,9 @@
<< ", " << Ptr->PrevUsed << "," << Ptr->NextUsed
<< ", " << Ptr->Link << "," << Ptr->Handle
<< ", " << (char*) Ptr->Object << " (" << hex
+#ifndef EXCLUDE_FROM_XARALX
<< Cache.BlockSize(Ptr)-UsedCacheBlockSize-cc_strlenBytes((char*)Ptr->Object)-1
+#endif
<< dec << ")" << endl ;
Ptr = Ptr->Next ;
}
Index: Kernel/fntcache.h
===================================================================
--- Kernel/fntcache.h (Revision 706)
+++ Kernel/fntcache.h (Arbeitskopie)
@@ -133,14 +133,14 @@
********************************************************************************************/
-// The simpler FontCache defined below is simply a wrapper around a GCache
+// The simpler FontCache defined below is simply a wrapper around a CamCache
class FontCache
{
// All data/methods must be static
public:
- // This method must be called before we can use the GCache
+ // This method must be called before we can use the CamCache
static BOOL Init();
static BOOL InitCalled; // = FALSE, set to TRUE only if Init function has been called
@@ -152,7 +152,7 @@
static BOOL GetPath(CharDescription& ChDesc, INT32** Points, BYTE** Types, UINT32 *Length);
// The path cache is used to map a Path Handle to path data
- static GCache* pPathCache;
+ static CamCache* pPathCache;
static BOOL GetBounds(DocRect* pBounds, CharDescription& CharDesc);
static BOOL CalcDefaultCharBounds(DocRect* pRect, CharDescription& CharDesc);
@@ -281,7 +281,7 @@
public:
- // This method must be called before we can use the GCache
+ // This method must be called before we can use the CamCache
static BOOL Init();
static BOOL InitCalled; // = FALSE, set to TRUE only if Init function has been called
@@ -324,7 +324,7 @@
INT32** Points, BYTE** Types, UINT32* Length);
// The path cache is used to map a Path Handle to path data
- static GCache* pPathCache;
+ static CamCache* pPathCache;
static PathHandleItem* AllocatePathHandle(UINT32 Key, CharDescription& ChDesc);