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