cedric's mmap patch

SVN revision: 23413
This commit is contained in:
Carsten Haitzler 2006-06-13 10:20:22 +00:00
parent 28dff2e36e
commit 3a85bfb709
6 changed files with 624 additions and 490 deletions

View File

@ -1,2 +1,3 @@
The Rasterman (Carsten Haitzler) <raster@rasterman.com>
David Goodlad <dgoodlad@gmail.com>
Cedric Bail <cedric.bail@free.fr>

View File

@ -126,18 +126,13 @@ extern "C" {
EAPI int eet_shutdown(void);
/**
* Turn cacheburst on/off
* Clear eet cache
*
* @param on Set this to 1 to turn on, 0 to turn off.
*
* This enables cacheburst mode. This is where eet will not free items from
* its internal share cache even when their references hit 0. This is
* intended to be enabled during bursts where eet may open several eet
* files over and over and over again (eg in initialization of an app) and
* thius this will avoid repeated openings. It will NOT respect changes
* on disk and if you open a LOT of files may use a lot of memory.
* Eet didn't free items by default. If you are under memory presure, just
* call this function to recall all memory that are not yet referenced anymore.
* The cache take care of modification on disk.
*/
EAPI void eet_cacheburst(int on);
EAPI void eet_clearcache(void);
/**
* Open an eet file on disk, and returns a handle to it.
@ -235,6 +230,26 @@ extern "C" {
*/
EAPI void *eet_read(Eet_File *ef, const char *name, int *size_ret);
/**
* Read a specified entry from an eet file and return data
* @param ef A valid eet file handle opened for reading.
* @param name Name of the entry. eg: "/base/file_i_want".
* @param size_ret Number of bytes read from entry and returned.
* @return The data stored in that entry in the eet file.
*
* This function finds an entry in the eet file that is stored under the
* name specified, and returns that data if not compressed and successful.
* NULL is returned if the lookup fails or if memory errors are
* encountered or if the data is comrpessed. The calling program must never
* call free() on the returned data. The number of bytes in the returned
* data chunk are placed in size_ret.
*
* If the eet file handle is not valid NULL is returned and size_ret is
* filled with 0.
*/
EAPI void *eet_read_direct (Eet_File *ef, const char *name, int *size_ret);
/**
* Write a specified entry to an eet file handle
* @param ef A valid eet file handle opened for writing.

View File

@ -46,4 +46,40 @@ void _eet_memfile_shutdown();
#define PATH_MAX 4096
#endif
/* caluclate hash table entry valu with bitmask size of hash_size */
static int
eet_hash_gen(const char *key, int hash_size)
{
int hash_num = 0;
int value, i;
unsigned char *ptr;
const int masks[9] =
{
0x00,
0x01,
0x03,
0x07,
0x0f,
0x1f,
0x3f,
0x7f,
0xff
};
/* no string - index 0 */
if (!key) return 0;
/* calc hash num */
for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr);
value;
ptr++, i++, value = (int)(*ptr))
hash_num ^= (value | (value << 8)) >> (i & 0x7);
/* mask it */
hash_num &= masks[hash_size];
/* return it */
return hash_num;
}
#endif

View File

@ -567,7 +567,7 @@ eet_data_chunk_put(Eet_Data_Chunk *chnk, Eet_Data_Stream *ds)
{
int *size;
int s;
int size_ret;
int size_ret = 0;
if (!chnk->data) return;
/* chunk head */
@ -588,37 +588,6 @@ eet_data_chunk_put(Eet_Data_Chunk *chnk, Eet_Data_Stream *ds)
/*---*/
static int
_eet_descriptor_hash_gen(char *key, int hash_size)
{
int hash_num = 0, i;
unsigned char *ptr;
const int masks[9] =
{
0x00,
0x01,
0x03,
0x07,
0x0f,
0x1f,
0x3f,
0x7f,
0xff
};
/* no string - index 0 */
if (!key) return 0;
/* calc hash num */
for (i = 0, ptr = (unsigned char *)key; *ptr; ptr++, i++)
hash_num ^= ((int)(*ptr) | ((int)(*ptr) << 8)) >> (i % 8);
/* mask it */
hash_num &= masks[hash_size];
/* return it */
return hash_num;
}
static void
_eet_descriptor_hash_new(Eet_Data_Descriptor *edd)
{
@ -632,7 +601,7 @@ _eet_descriptor_hash_new(Eet_Data_Descriptor *edd)
int hash;
ede = &(edd->elements.set[i]);
hash = _eet_descriptor_hash_gen((char *) ede->name, 6);
hash = eet_hash_gen((char *) ede->name, 6);
if (!edd->elements.hash.buckets[hash].element)
edd->elements.hash.buckets[hash].element = ede;
else
@ -673,7 +642,7 @@ _eet_descriptor_hash_find(Eet_Data_Descriptor *edd, char *name)
int hash;
Eet_Data_Descriptor_Hash *bucket;
hash = _eet_descriptor_hash_gen(name, 6);
hash = eet_hash_gen(name, 6);
if (!edd->elements.hash.buckets[hash].element) return NULL;
if (!strcmp(edd->elements.hash.buckets[hash].element->name, name))
return edd->elements.hash.buckets[hash].element;
@ -858,12 +827,20 @@ eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, char *name)
{
void *data_dec;
void *data;
int size;
int size;
int required_free = 0;
data = eet_read(ef, name, &size);
if (!data) return NULL;
data = eet_read_direct (ef, name, &size);
if (!data)
{
required_free = 1;
data = eet_read(ef, name, &size);
if (!data) return NULL;
}
data_dec = eet_data_descriptor_decode(edd, data, size);
free(data);
if (required_free)
free(data);
return data_dec;
}

View File

@ -716,14 +716,24 @@ eet_data_image_read(Eet_File *ef, const char *name,
unsigned int *w, unsigned int *h, int *alpha,
int *compress, int *quality, int *lossy)
{
void *data;
int size;
void *data;
int size;
unsigned int *d = NULL;
int free_data = 0;
data = eet_read_direct (ef, name, &size);
if (!data)
{
data = eet_read(ef, name, &size);
free_data = 1;
}
data = eet_read(ef, name, &size);
if (!data) return NULL;
d = eet_data_image_decode(data, size, w, h, alpha, compress, quality, lossy);
free(data);
if (free_data)
free(data);
return d;
}
@ -732,14 +742,23 @@ eet_data_image_header_read(Eet_File *ef, const char *name,
unsigned int *w, unsigned int *h, int *alpha,
int *compress, int *quality, int *lossy)
{
void *data;
int size;
int d;
void *data = NULL;
int size = 0;
int d;
int free_data = 0;
data = eet_read_direct (ef, name, &size);
if (!data)
{
data = eet_read(ef, name, &size);
free_data = 1;
}
data = eet_read(ef, name, &size);
if (!data) return 0;
d = eet_data_image_header_decode(data, size, w, h, alpha, compress, quality, lossy);
free(data);
if (free_data)
free(data);
return d;
}

File diff suppressed because it is too large Load Diff