summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-05-20 07:06:57 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-05-20 07:06:57 +0000
commit2aab1519194f08c2a6ee563b2585cf47b024df56 (patch)
tree29b1f957eed04e073314b5af7dd8662dd1610895
parent68d5592136aee135477598c32d49edf904321ee2 (diff)
edje: reduce memcpy in edje_cc by using Eina_File.
SVN revision: 71242
Diffstat (limited to '')
-rw-r--r--legacy/edje/ChangeLog4
-rw-r--r--legacy/edje/NEWS1
-rw-r--r--legacy/edje/src/bin/edje_cc_out.c168
3 files changed, 68 insertions, 105 deletions
diff --git a/legacy/edje/ChangeLog b/legacy/edje/ChangeLog
index 3a59a305c6..3ff4a2bfdc 100644
--- a/legacy/edje/ChangeLog
+++ b/legacy/edje/ChangeLog
@@ -462,3 +462,7 @@
462 462
463 * Fix table and text when fixed point is turned on. 463 * Fix table and text when fixed point is turned on.
464 * Clamp image tween to never underflow also. 464 * Clamp image tween to never underflow also.
465
4662012-05-20 Cedric Bail
467
468 * Use Eina_File instead of fopen when possible in edje_cc.
diff --git a/legacy/edje/NEWS b/legacy/edje/NEWS
index 3b895dac03..e46985a057 100644
--- a/legacy/edje/NEWS
+++ b/legacy/edje/NEWS
@@ -10,6 +10,7 @@ Additions:
10 10
11Improvements: 11Improvements:
12 * Allocate once and reuse Evas_Map. 12 * Allocate once and reuse Evas_Map.
13 * Make edje_cc faster by improving the parser, mapping file in memory and using threads.
13 14
14Fixes: 15Fixes:
15 * Add missing files in the tarballs. 16 * Add missing files in the tarballs.
diff --git a/legacy/edje/src/bin/edje_cc_out.c b/legacy/edje/src/bin/edje_cc_out.c
index b334091ae8..30ea4c89ec 100644
--- a/legacy/edje/src/bin/edje_cc_out.c
+++ b/legacy/edje/src/bin/edje_cc_out.c
@@ -418,99 +418,68 @@ static void
418data_thread_fonts(void *data, Ecore_Thread *thread __UNUSED__) 418data_thread_fonts(void *data, Ecore_Thread *thread __UNUSED__)
419{ 419{
420 Fonts_Write *fc = data; 420 Fonts_Write *fc = data;
421 void *fdata = NULL;
422 int fsize = 0;
423 Eina_List *ll; 421 Eina_List *ll;
424 FILE *f; 422 Eina_File *f = NULL;
423 void *m = NULL;
425 int bytes = 0; 424 int bytes = 0;
426 char buf[PATH_MAX]; 425 char buf[PATH_MAX];
427 char buf2[PATH_MAX]; 426 char buf2[PATH_MAX];
428 427
429 f = fopen(fc->fn->file, "rb"); 428 f = eina_file_open(fc->fn->file, 0);
430 if (f) 429 if (f)
431 { 430 {
432 long pos;
433
434 using_file(fc->fn->file); 431 using_file(fc->fn->file);
435 fseek(f, 0, SEEK_END); 432 m = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
436 pos = ftell(f);
437 rewind(f);
438 fdata = malloc(pos);
439 if (fdata)
440 {
441 if (fread(fdata, pos, 1, f) != 1)
442 {
443 snprintf(buf, sizeof(buf),
444 "Unable to read all of font file \"%s\"\n",
445 fc->fn->file);
446 fc->errstr = strdup(buf);
447 return;
448 }
449 fsize = pos;
450 }
451 fclose(f);
452 } 433 }
453 else 434 else
454 { 435 {
455 char *dat; 436 char *dat;
456 437
457 EINA_LIST_FOREACH(fnt_dirs, ll, dat) 438 EINA_LIST_FOREACH(fnt_dirs, ll, dat)
458 { 439 {
459 snprintf(buf, sizeof(buf), "%s/%s", dat, fc->fn->file); 440 snprintf(buf, sizeof(buf), "%s/%s", dat, fc->fn->file);
460 f = fopen(buf, "rb"); 441 f = eina_file_open(buf, 0);
461 if (f) 442 if (f)
462 { 443 {
463 long pos;
464
465 using_file(buf); 444 using_file(buf);
466 fseek(f, 0, SEEK_END); 445 m = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
467 pos = ftell(f); 446 if (m) break;
468 rewind(f); 447 eina_file_close(f);
469 fdata = malloc(pos); 448 f = NULL;
470 if (fdata)
471 {
472 if (fread(fdata, pos, 1, f) != 1)
473 {
474 snprintf(buf2, sizeof(buf2),
475 "Unable to read all of font file \"%s\"\n",
476 buf);
477 fc->errstr = strdup(buf2);
478 return;
479 }
480 fsize = pos;
481 }
482 fclose(f);
483 if (fdata) break;
484 } 449 }
485 } 450 }
486 } 451 }
487 if (!fdata) 452 if (!m)
488 { 453 {
454 if (f) eina_file_close(f);
489 snprintf(buf, sizeof(buf), 455 snprintf(buf, sizeof(buf),
490 "Unable to load font part \"%s\" entry to %s \n", 456 "Unable to load font part \"%s\" entry to %s \n",
491 fc->fn->file, file_out); 457 fc->fn->file, file_out);
492 fc->errstr = strdup(buf); 458 fc->errstr = strdup(buf);
493 return; 459 return;
494 } 460 }
495 else 461
462 snprintf(buf, sizeof(buf), "edje/fonts/%s", fc->fn->name);
463 bytes = eet_write(fc->ef, buf, m, eina_file_size_get(f), compress_mode);
464
465 if (bytes <= 0 || eina_file_map_faulted(f, m))
496 { 466 {
497 snprintf(buf, sizeof(buf), "edje/fonts/%s", fc->fn->name); 467 eina_file_map_free(f, m);
498 bytes = eet_write(fc->ef, buf, fdata, fsize, compress_mode); 468 eina_file_close(f);
499 if (bytes <= 0) 469 snprintf(buf2, sizeof(buf2),
500 { 470 "Unable to write font part \"%s\" as \"%s\" "
501 snprintf(buf2, sizeof(buf2), 471 "part entry to %s \n", fc->fn->file, buf, file_out);
502 "Unable to write font part \"%s\" as \"%s\" " 472 fc->errstr = strdup(buf2);
503 "part entry to %s \n", fc->fn->file, buf, file_out); 473 return;
504 fc->errstr = strdup(buf2);
505 return;
506 }
507 if (verbose)
508 printf("%s: Wrote %9i bytes (%4iKb) for \"%s\" font entry \"%s\" compress: [real: %2.1f%%]\n",
509 progname, bytes, (bytes + 512) / 1024, buf, fc->fn->file,
510 100 - (100 * (double)bytes) / ((double)(fsize))
511 );
512 free(fdata);
513 } 474 }
475
476 if (verbose)
477 printf("%s: Wrote %9i bytes (%4iKb) for \"%s\" font entry \"%s\" compress: [real: %2.1f%%]\n",
478 progname, bytes, (bytes + 512) / 1024, buf, fc->fn->file,
479 100 - (100 * (double)bytes) / ((double)(eina_file_size_get(f)))
480 );
481 eina_file_map_free(f, m);
482 eina_file_close(f);
514} 483}
515 484
516static void 485static void
@@ -539,7 +508,7 @@ data_write_fonts(Eet_File *ef, int *font_num)
539 EINA_ITERATOR_FOREACH(it, fn) 508 EINA_ITERATOR_FOREACH(it, fn)
540 { 509 {
541 Fonts_Write *fc; 510 Fonts_Write *fc;
542 511
543 fc = calloc(1, sizeof(Fonts_Write)); 512 fc = calloc(1, sizeof(Fonts_Write));
544 if (!fc) continue; 513 if (!fc) continue;
545 fc->ef = ef; 514 fc->ef = ef;
@@ -654,7 +623,7 @@ data_thread_image(void *data, Ecore_Thread *thread __UNUSED__)
654 if ((iw->data) && (iw->w > 0) && (iw->h > 0)) 623 if ((iw->data) && (iw->w > 0) && (iw->h > 0))
655 { 624 {
656 int mode, qual; 625 int mode, qual;
657 626
658 snprintf(buf, sizeof(buf), "edje/images/%i", iw->img->id); 627 snprintf(buf, sizeof(buf), "edje/images/%i", iw->img->id);
659 qual = 80; 628 qual = 80;
660 if ((iw->img->source_type == EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT) && 629 if ((iw->img->source_type == EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT) &&
@@ -726,7 +695,6 @@ data_thread_image(void *data, Ecore_Thread *thread __UNUSED__)
726 iw->errstr = strdup(buf); 695 iw->errstr = strdup(buf);
727 return; 696 return;
728 } 697 }
729
730 } 698 }
731 else 699 else
732 { 700 {
@@ -737,12 +705,12 @@ data_thread_image(void *data, Ecore_Thread *thread __UNUSED__)
737 iw->errstr = strdup(buf); 705 iw->errstr = strdup(buf);
738 return; 706 return;
739 } 707 }
740 708
741 if (verbose) 709 if (verbose)
742 { 710 {
743 struct stat st; 711 struct stat st;
744 712
745 if (!iw->path || (!stat(iw->path, &st))) st.st_size = 0; 713 if (!iw->path || (stat(iw->path, &st))) st.st_size = 0;
746 printf("%s: Wrote %9i bytes (%4iKb) for \"%s\" image entry \"%s\" compress: [raw: %2.1f%%] [real: %2.1f%%]\n", 714 printf("%s: Wrote %9i bytes (%4iKb) for \"%s\" image entry \"%s\" compress: [raw: %2.1f%%] [real: %2.1f%%]\n",
747 progname, bytes, (bytes + 512) / 1024, buf, iw->img->entry, 715 progname, bytes, (bytes + 512) / 1024, buf, iw->img->entry,
748 100 - (100 * (double)bytes) / ((double)(iw->w * iw->h * 4)), 716 100 - (100 * (double)bytes) / ((double)(iw->w * iw->h * 4)),
@@ -874,66 +842,56 @@ data_thread_sounds(void *data, Ecore_Thread *thread __UNUSED__)
874 char *dir_path = NULL; 842 char *dir_path = NULL;
875 char snd_path[PATH_MAX]; 843 char snd_path[PATH_MAX];
876 char sndid_str[15]; 844 char sndid_str[15];
877 void *fdata; 845 Eina_File *f = NULL;
878 FILE *fp = NULL; 846 void *m = NULL;
879 struct stat st;
880 int size = 0;
881 int bytes = 0; 847 int bytes = 0;
882 848
883 memset(&st, 0, sizeof(struct stat));
884 // Search the Sound file in all the -sd ( sound directory ) 849 // Search the Sound file in all the -sd ( sound directory )
885 EINA_LIST_FOREACH(snd_dirs, ll, dir_path) 850 EINA_LIST_FOREACH(snd_dirs, ll, dir_path)
886 { 851 {
887 snprintf((char *)snd_path, sizeof(snd_path), "%s/%s", dir_path, 852 snprintf((char *)snd_path, sizeof(snd_path), "%s/%s", dir_path,
888 sw->sample->snd_src); 853 sw->sample->snd_src);
889 stat(snd_path, &st); 854 f = eina_file_open(snd_path, 0);
890 if (st.st_size) break; 855 if (f) break;
891 } 856 }
892 if (!st.st_size) 857 if (!f)
893 { 858 {
894 snprintf((char *)snd_path, sizeof(snd_path), "%s", 859 snprintf((char *)snd_path, sizeof(snd_path), "%s",
895 sw->sample->snd_src); 860 sw->sample->snd_src);
896 stat(snd_path, &st); 861 f = eina_file_open(snd_path, 0);
897 }
898 size = st.st_size;
899 if (!size)
900 {
901 ERR("%s: Error. Unable to load sound source file : %s",
902 progname, sw->sample->snd_src);
903 exit(-1);
904 } 862 }
905#ifdef HAVE_LIBSNDFILE 863#ifdef HAVE_LIBSNDFILE
864 if (f) eina_file_close(f);
906 enc_info = _edje_multisense_encode(snd_path, sw->sample, 865 enc_info = _edje_multisense_encode(snd_path, sw->sample,
907 sw->sample->quality); 866 sw->sample->quality);
908 stat(enc_info->file, &st); 867 f = eina_file_open(enc_info->file, 0);
909 size = st.st_size; 868 if (f) using_file(enc_info->file);
910 fp = fopen(enc_info->file, "rb");
911 if (fp) using_file(enc_info->file);
912#else 869#else
913 fp = fopen(snd_path, "rb"); 870 if (f) using_file(snd_path);
914 if (fp) using_file(snd_path);
915#endif 871#endif
916 if (!fp) 872 if (!f)
917 { 873 {
918 ERR("%s: Error: Unable to load sound data of: %s", 874 ERR("%s: Error: Unable to load sound data of: %s",
919 progname, sw->sample->name); 875 progname, sw->sample->name);
920 exit(-1); 876 exit(-1);
921 } 877 }
922 878
923 snprintf(sndid_str, sizeof(sndid_str), "edje/sounds/%i", sw->sample->id); 879 snprintf(sndid_str, sizeof(sndid_str), "edje/sounds/%i", sw->sample->id);
924 fdata = malloc(size); 880 m = eina_file_map_all(f, EINA_FILE_WILLNEED);
925 if (!fdata) 881 if (m)
926 { 882 {
927 ERR("%s: Error. %s:%i while allocating memory to load file \"%s\"", 883 bytes = eet_write(sw->ef, sndid_str, m, eina_file_size_get(f),
928 progname, file_in, line, snd_path); 884 EET_COMPRESSION_NONE);
929 exit(-1); 885 if (eina_file_map_faulted(f, m))
886 {
887 ERR("%s: Error: File access error when reading '%s'",
888 progname, eina_file_filename_get(f));
889 exit(-1);
890 }
891 eina_file_map_free(f, m);
930 } 892 }
931 if (fread(fdata, size, 1, fp)) 893 eina_file_close(f);
932 bytes = eet_write(sw->ef, sndid_str, fdata, size, 894
933 EET_COMPRESSION_NONE);
934 free(fdata);
935 fclose(fp);
936
937#ifdef HAVE_LIBSNDFILE 895#ifdef HAVE_LIBSNDFILE
938 //If encoded temporary file, delete it. 896 //If encoded temporary file, delete it.
939 if (enc_info->encoded) unlink(enc_info->file); 897 if (enc_info->encoded) unlink(enc_info->file);
@@ -1587,7 +1545,7 @@ data_write(void)
1587 check_groups(ef); 1545 check_groups(ef);
1588 1546
1589 ecore_thread_max_set(ecore_thread_max_get() * 2); 1547 ecore_thread_max_set(ecore_thread_max_get() * 2);
1590 1548
1591 t = ecore_time_get(); 1549 t = ecore_time_get();
1592 data_write_header(ef); 1550 data_write_header(ef);
1593 if (verbose) 1551 if (verbose)