forked from enlightenment/efl
edje: reduce memcpy in edje_cc by using Eina_File.
SVN revision: 71242
This commit is contained in:
parent
68d5592136
commit
2aab151919
|
@ -462,3 +462,7 @@
|
|||
|
||||
* Fix table and text when fixed point is turned on.
|
||||
* Clamp image tween to never underflow also.
|
||||
|
||||
2012-05-20 Cedric Bail
|
||||
|
||||
* Use Eina_File instead of fopen when possible in edje_cc.
|
||||
|
|
|
@ -10,6 +10,7 @@ Additions:
|
|||
|
||||
Improvements:
|
||||
* Allocate once and reuse Evas_Map.
|
||||
* Make edje_cc faster by improving the parser, mapping file in memory and using threads.
|
||||
|
||||
Fixes:
|
||||
* Add missing files in the tarballs.
|
||||
|
|
|
@ -418,37 +418,18 @@ static void
|
|||
data_thread_fonts(void *data, Ecore_Thread *thread __UNUSED__)
|
||||
{
|
||||
Fonts_Write *fc = data;
|
||||
void *fdata = NULL;
|
||||
int fsize = 0;
|
||||
Eina_List *ll;
|
||||
FILE *f;
|
||||
Eina_File *f = NULL;
|
||||
void *m = NULL;
|
||||
int bytes = 0;
|
||||
char buf[PATH_MAX];
|
||||
char buf2[PATH_MAX];
|
||||
|
||||
f = fopen(fc->fn->file, "rb");
|
||||
f = eina_file_open(fc->fn->file, 0);
|
||||
if (f)
|
||||
{
|
||||
long pos;
|
||||
|
||||
using_file(fc->fn->file);
|
||||
fseek(f, 0, SEEK_END);
|
||||
pos = ftell(f);
|
||||
rewind(f);
|
||||
fdata = malloc(pos);
|
||||
if (fdata)
|
||||
{
|
||||
if (fread(fdata, pos, 1, f) != 1)
|
||||
{
|
||||
snprintf(buf, sizeof(buf),
|
||||
"Unable to read all of font file \"%s\"\n",
|
||||
fc->fn->file);
|
||||
fc->errstr = strdup(buf);
|
||||
return;
|
||||
}
|
||||
fsize = pos;
|
||||
}
|
||||
fclose(f);
|
||||
m = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -457,60 +438,48 @@ data_thread_fonts(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
EINA_LIST_FOREACH(fnt_dirs, ll, dat)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "%s/%s", dat, fc->fn->file);
|
||||
f = fopen(buf, "rb");
|
||||
f = eina_file_open(buf, 0);
|
||||
if (f)
|
||||
{
|
||||
long pos;
|
||||
|
||||
using_file(buf);
|
||||
fseek(f, 0, SEEK_END);
|
||||
pos = ftell(f);
|
||||
rewind(f);
|
||||
fdata = malloc(pos);
|
||||
if (fdata)
|
||||
{
|
||||
if (fread(fdata, pos, 1, f) != 1)
|
||||
{
|
||||
snprintf(buf2, sizeof(buf2),
|
||||
"Unable to read all of font file \"%s\"\n",
|
||||
buf);
|
||||
fc->errstr = strdup(buf2);
|
||||
return;
|
||||
}
|
||||
fsize = pos;
|
||||
}
|
||||
fclose(f);
|
||||
if (fdata) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!fdata)
|
||||
m = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||
if (m) break;
|
||||
eina_file_close(f);
|
||||
f = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!m)
|
||||
{
|
||||
if (f) eina_file_close(f);
|
||||
snprintf(buf, sizeof(buf),
|
||||
"Unable to load font part \"%s\" entry to %s \n",
|
||||
fc->fn->file, file_out);
|
||||
fc->errstr = strdup(buf);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
snprintf(buf, sizeof(buf), "edje/fonts/%s", fc->fn->name);
|
||||
bytes = eet_write(fc->ef, buf, fdata, fsize, compress_mode);
|
||||
if (bytes <= 0)
|
||||
bytes = eet_write(fc->ef, buf, m, eina_file_size_get(f), compress_mode);
|
||||
|
||||
if (bytes <= 0 || eina_file_map_faulted(f, m))
|
||||
{
|
||||
eina_file_map_free(f, m);
|
||||
eina_file_close(f);
|
||||
snprintf(buf2, sizeof(buf2),
|
||||
"Unable to write font part \"%s\" as \"%s\" "
|
||||
"part entry to %s \n", fc->fn->file, buf, file_out);
|
||||
fc->errstr = strdup(buf2);
|
||||
return;
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
printf("%s: Wrote %9i bytes (%4iKb) for \"%s\" font entry \"%s\" compress: [real: %2.1f%%]\n",
|
||||
progname, bytes, (bytes + 512) / 1024, buf, fc->fn->file,
|
||||
100 - (100 * (double)bytes) / ((double)(fsize))
|
||||
100 - (100 * (double)bytes) / ((double)(eina_file_size_get(f)))
|
||||
);
|
||||
free(fdata);
|
||||
}
|
||||
eina_file_map_free(f, m);
|
||||
eina_file_close(f);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -726,7 +695,6 @@ data_thread_image(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
iw->errstr = strdup(buf);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -742,7 +710,7 @@ data_thread_image(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
{
|
||||
struct stat st;
|
||||
|
||||
if (!iw->path || (!stat(iw->path, &st))) st.st_size = 0;
|
||||
if (!iw->path || (stat(iw->path, &st))) st.st_size = 0;
|
||||
printf("%s: Wrote %9i bytes (%4iKb) for \"%s\" image entry \"%s\" compress: [raw: %2.1f%%] [real: %2.1f%%]\n",
|
||||
progname, bytes, (bytes + 512) / 1024, buf, iw->img->entry,
|
||||
100 - (100 * (double)bytes) / ((double)(iw->w * iw->h * 4)),
|
||||
|
@ -874,46 +842,34 @@ data_thread_sounds(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
char *dir_path = NULL;
|
||||
char snd_path[PATH_MAX];
|
||||
char sndid_str[15];
|
||||
void *fdata;
|
||||
FILE *fp = NULL;
|
||||
struct stat st;
|
||||
int size = 0;
|
||||
Eina_File *f = NULL;
|
||||
void *m = NULL;
|
||||
int bytes = 0;
|
||||
|
||||
memset(&st, 0, sizeof(struct stat));
|
||||
// Search the Sound file in all the -sd ( sound directory )
|
||||
EINA_LIST_FOREACH(snd_dirs, ll, dir_path)
|
||||
{
|
||||
snprintf((char *)snd_path, sizeof(snd_path), "%s/%s", dir_path,
|
||||
sw->sample->snd_src);
|
||||
stat(snd_path, &st);
|
||||
if (st.st_size) break;
|
||||
f = eina_file_open(snd_path, 0);
|
||||
if (f) break;
|
||||
}
|
||||
if (!st.st_size)
|
||||
if (!f)
|
||||
{
|
||||
snprintf((char *)snd_path, sizeof(snd_path), "%s",
|
||||
sw->sample->snd_src);
|
||||
stat(snd_path, &st);
|
||||
}
|
||||
size = st.st_size;
|
||||
if (!size)
|
||||
{
|
||||
ERR("%s: Error. Unable to load sound source file : %s",
|
||||
progname, sw->sample->snd_src);
|
||||
exit(-1);
|
||||
f = eina_file_open(snd_path, 0);
|
||||
}
|
||||
#ifdef HAVE_LIBSNDFILE
|
||||
if (f) eina_file_close(f);
|
||||
enc_info = _edje_multisense_encode(snd_path, sw->sample,
|
||||
sw->sample->quality);
|
||||
stat(enc_info->file, &st);
|
||||
size = st.st_size;
|
||||
fp = fopen(enc_info->file, "rb");
|
||||
if (fp) using_file(enc_info->file);
|
||||
f = eina_file_open(enc_info->file, 0);
|
||||
if (f) using_file(enc_info->file);
|
||||
#else
|
||||
fp = fopen(snd_path, "rb");
|
||||
if (fp) using_file(snd_path);
|
||||
if (f) using_file(snd_path);
|
||||
#endif
|
||||
if (!fp)
|
||||
if (!f)
|
||||
{
|
||||
ERR("%s: Error: Unable to load sound data of: %s",
|
||||
progname, sw->sample->name);
|
||||
|
@ -921,18 +877,20 @@ data_thread_sounds(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
}
|
||||
|
||||
snprintf(sndid_str, sizeof(sndid_str), "edje/sounds/%i", sw->sample->id);
|
||||
fdata = malloc(size);
|
||||
if (!fdata)
|
||||
m = eina_file_map_all(f, EINA_FILE_WILLNEED);
|
||||
if (m)
|
||||
{
|
||||
ERR("%s: Error. %s:%i while allocating memory to load file \"%s\"",
|
||||
progname, file_in, line, snd_path);
|
||||
bytes = eet_write(sw->ef, sndid_str, m, eina_file_size_get(f),
|
||||
EET_COMPRESSION_NONE);
|
||||
if (eina_file_map_faulted(f, m))
|
||||
{
|
||||
ERR("%s: Error: File access error when reading '%s'",
|
||||
progname, eina_file_filename_get(f));
|
||||
exit(-1);
|
||||
}
|
||||
if (fread(fdata, size, 1, fp))
|
||||
bytes = eet_write(sw->ef, sndid_str, fdata, size,
|
||||
EET_COMPRESSION_NONE);
|
||||
free(fdata);
|
||||
fclose(fp);
|
||||
eina_file_map_free(f, m);
|
||||
}
|
||||
eina_file_close(f);
|
||||
|
||||
#ifdef HAVE_LIBSNDFILE
|
||||
//If encoded temporary file, delete it.
|
||||
|
|
Loading…
Reference in New Issue