summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvi Levin <avi.levin@samsung.com>2015-03-31 17:18:27 +0300
committerAvi Levin <avi.levin@samsung.com>2015-04-01 11:10:10 +0300
commitd8c44ee7f64a68738adb7e74b555c03442645aea (patch)
tree0c68d7d5aaf50fd36faf2a620460a3aba15f730c
parent3f7c4978f3c05d827fffb9d1378165f4a89f50c0 (diff)
eo: working version that combines linear and ordered searchdevs/avilog/callbacks_by_events
If we have less than 7 members we will use linear search. @feature
-rw-r--r--src/lib/eo/eo_base_class.c134
1 files changed, 49 insertions, 85 deletions
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index b00225ae23..5d7949f519 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -482,20 +482,17 @@ _legacy_events_hash_free_cb(void *_desc)
482struct _Eo_Callback_Description 482struct _Eo_Callback_Description
483{ 483{
484 Eo_Callback_Description *next; 484 Eo_Callback_Description *next;
485//Eina_Stringshare *event_name;
486
487 union 485 union
488 { 486 {
489 Eo_Callback_Array_Item item; 487 Eo_Callback_Array_Item item;
490 const Eo_Callback_Array_Item *item_array; 488 const Eo_Callback_Array_Item *item_array;
491 } items; 489 } items;
492 490 const Eo_Callback_Array_Item *item_array;
493 void *func_data; 491 void *func_data;
494 Eo_Callback_Priority priority; 492 Eo_Callback_Priority priority;
495 493
496 Eina_Bool delete_me : 1; 494 Eina_Bool delete_me : 1;
497 Eina_Bool func_array : 1; 495 Eina_Bool func_array : 1;
498 Eina_Bool is_legacy : 1;
499 Eina_Bool is_legacy_counter : 1; 496 Eina_Bool is_legacy_counter : 1;
500 497
501}; 498};
@@ -529,8 +526,7 @@ _eo_callback_remove(Eo_Event_Callbacks *ec, Eo_Callback_Description *cb)
529 else 526 else
530 { 527 {
531 pitr = titr; 528 pitr = titr;
532 } 529 }
533
534 } 530 }
535} 531}
536/* Actually remove, doesn't care about walking list, or delete_me */ 532/* Actually remove, doesn't care about walking list, or delete_me */
@@ -580,44 +576,6 @@ _eo_callbacks_clear(Eo_Base_Data *pd)
580 } 576 }
581} 577}
582 578
583
584
585static Eina_Bool
586_cb_desc_match(const Eo_Event_Description *a, const Eo_Event_Description *b)
587{
588 if (!a)
589 return EINA_FALSE;
590
591 /* If either is legacy, fallback to string comparison. */
592 if ((a->doc == _legacy_event_desc) || (b->doc == _legacy_event_desc))
593 {
594 /* Take stringshare shortcut if both are legacy */
595 if (a->doc == b->doc)
596 {
597 if (a->name == b->name){
598 // printf("cb_desc same name after name pointer cmp %s\n", a->name);
599 return EINA_TRUE;
600 }
601 return EINA_FALSE;
602
603 }
604 else
605 {
606 if(strcmp(a->name, b->name)==0){
607 // printf("cb_desc same name after strcmp %s\n", a->name);
608 return EINA_TRUE;
609 }
610 else{
611 // printf("cb_desc **not** same name after strcmp %s\n", a->name);
612 return EINA_FALSE;
613 }
614 }
615 }
616 else
617 {
618 return (a == b);
619 }
620}
621static void 579static void
622_eo_callbacks_list_sorted_insert( Eo_Event_Callbacks *ec, Eo_Callback_Description *cb) 580_eo_callbacks_list_sorted_insert( Eo_Event_Callbacks *ec, Eo_Callback_Description *cb)
623{ 581{
@@ -671,7 +629,6 @@ _eo_callbacks_sorted_insert(Eo_Base_Data *pd, Eo_Callback_Description *cb, const
671 } 629 }
672 pd->callbacks_counter++;//avi debug 630 pd->callbacks_counter++;//avi debug
673 631
674 cb->items.item.desc = desc;
675 Eina_Stringshare *event_name; 632 Eina_Stringshare *event_name;
676 if (desc->doc != _legacy_event_desc) 633 if (desc->doc != _legacy_event_desc)
677 { 634 {
@@ -683,35 +640,35 @@ _eo_callbacks_sorted_insert(Eo_Base_Data *pd, Eo_Callback_Description *cb, const
683 regular_events_inserted++; 640 regular_events_inserted++;
684 } 641 }
685 Eo_Event_Callbacks *cbs; 642 Eo_Event_Callbacks *cbs;
686 Eo_Event_Callbacks ec = { desc,event_name , cb }; 643 Eo_Event_Callbacks ec = { desc, event_name , cb };
687 644
688 cb->next=NULL; 645 cb->next=NULL;
689// int index = eina_inarray_search_sorted ( pd->callbacks, &ec , _eo_base_event_compare ); 646 int index = eina_inarray_search_sorted ( pd->callbacks, &ec , _eo_base_event_compare );
690 EINA_INARRAY_FOREACH(pd->callbacks, cbs) 647/* EINA_INARRAY_FOREACH(pd->callbacks, cbs)
691 { 648 {
692 // if(_cb_desc_match(desc, cbs->event)) 649 // if(_cb_desc_match(desc, cbs->event))
693 if(event_name == cbs->event_name) 650 if(event_name == cbs->event_name)
694 { 651 {
695 _eo_callbacks_list_sorted_insert(cbs, cb); 652 _eo_callbacks_list_sorted_insert(cbs, cb);
696 if (desc->doc != _legacy_event_desc) 653 if (desc->doc != _legacy_event_desc)
697 eina_stringshare_del(event_name); 654 eina_stringshare_del(event_name);
698 655
699 return; 656 return;
700 } 657 }
701 } 658 }*/
702 /*
703 if(index !=-1){
704 cbs =eina_inarray_nth(pd->callbacks , index );
705 _eo_callbacks_list_sorted_insert(cbs, cb);
706 if (desc->doc != _legacy_event_desc)
707 eina_stringshare_del(event_name);
708 659
709 return; 660 if(index !=-1){
710 } 661 cbs =eina_inarray_nth(pd->callbacks , index );
711*/ 662 _eo_callbacks_list_sorted_insert(cbs, cb);
663 if (desc->doc != _legacy_event_desc)
664 eina_stringshare_del(event_name);
665
666 return;
667 }
712 668
713 eina_inarray_push(pd->callbacks, &ec); 669
714// eina_inarray_insert_sorted(pd->callbacks , &ec , _eo_base_event_compare ); 670 // eina_inarray_push(pd->callbacks, &ec);
671 eina_inarray_insert_sorted(pd->callbacks , &ec , _eo_base_event_compare );
715 672
716} 673}
717 674
@@ -727,7 +684,7 @@ EOLIAN static void _eo_base_event_callback_priority_add(Eo *obj, Eo_Base_Data *p
727 cb->func_data = (void *) data; 684 cb->func_data = (void *) data;
728 cb->priority = priority; 685 cb->priority = priority;
729 cb->func_array = EINA_FALSE; 686 cb->func_array = EINA_FALSE;
730 cb->items.item_array = NULL; 687
731 cb->delete_me = EINA_FALSE; 688 cb->delete_me = EINA_FALSE;
732 _eo_callbacks_sorted_insert(pd, cb, desc); 689 _eo_callbacks_sorted_insert(pd, cb, desc);
733 690
@@ -788,7 +745,7 @@ _eo_base_event_callback_array_priority_add(Eo *obj, Eo_Base_Data *pd,
788 745
789 cb->func_data = (void *) user_data; 746 cb->func_data = (void *) user_data;
790 cb->priority = priority; 747 cb->priority = priority;
791 cb->items.item_array = array; 748 cb->item_array = array;
792 cb->func_array = EINA_TRUE; 749 cb->func_array = EINA_TRUE;
793 cb->delete_me = EINA_FALSE; 750 cb->delete_me = EINA_FALSE;
794 _eo_callbacks_sorted_insert(pd, cb,it->desc); 751 _eo_callbacks_sorted_insert(pd, cb,it->desc);
@@ -814,7 +771,7 @@ _eo_base_event_callback_array_del(Eo *obj, Eo_Base_Data *pd,
814 { 771 {
815 for (cb = cbs->callbacks; cb; cb = cb->next) 772 for (cb = cbs->callbacks; cb; cb = cb->next)
816 { 773 {
817 if ((cb->items.item_array == array) && (cb->func_data == user_data)) 774 if ((cb->item_array == array) && (cb->func_data == user_data))
818 { 775 {
819 cb->delete_me = EINA_TRUE; 776 cb->delete_me = EINA_TRUE;
820 pd->deletions_waiting = EINA_TRUE; 777 pd->deletions_waiting = EINA_TRUE;
@@ -865,24 +822,29 @@ _eo_base_event_callback_call(Eo *obj_id, Eo_Base_Data *pd,
865 event_name = desc->name; 822 event_name = desc->name;
866 } 823 }
867 Eo_Event_Callbacks ec = { desc,event_name , NULL }; 824 Eo_Event_Callbacks ec = { desc,event_name , NULL };
868//int index = eina_inarray_search_sorted ( pd->callbacks, &ec , _eo_base_event_compare ); 825 if( pd->callbacks->len < 7 ){ //if small array simple search will be faster
869 826 EINA_INARRAY_FOREACH(pd->callbacks, cbs)
870 EINA_INARRAY_FOREACH(pd->callbacks, cbs)
871 {
872 pd->called_loop_counter++;//avi debug
873 // if(_cb_desc_match(desc, cbs->event))
874 if(event_name == cbs->event_name)
875 { 827 {
876 found = EINA_TRUE; 828 pd->called_loop_counter++;//avi debug
877 break; 829 // if(_cb_desc_match(desc, cbs->event))
830 if(event_name == cbs->event_name)
831 {
832 found = EINA_TRUE;
833 break;
834 }
878 } 835 }
879 } 836 if(found==EINA_FALSE) {pd->called_sum_clocks +=clock()-start_time;//avi dbg
837 return EINA_FALSE;}
880 838
881 if(found==EINA_FALSE) {pd->called_sum_clocks +=clock()-start_time;//avi dbg 839 }
882 return EINA_FALSE;} 840 else{
841 int index = eina_inarray_search_sorted ( pd->callbacks, &ec , _eo_base_event_compare );
883 842
884// cbs =eina_inarray_nth(pd->callbacks , index ); 843 if(index==-1) {pd->called_sum_clocks +=clock()-start_time;//avi dbg
844 return EINA_FALSE;}
885 845
846 cbs =eina_inarray_nth(pd->callbacks , index );
847 }
886 ret = EINA_TRUE; 848 ret = EINA_TRUE;
887 849
888 _eo_ref(obj); 850 _eo_ref(obj);
@@ -890,9 +852,11 @@ _eo_base_event_callback_call(Eo *obj_id, Eo_Base_Data *pd,
890 852
891 for (cb = cbs->callbacks; cb; cb = cb->next) 853 for (cb = cbs->callbacks; cb; cb = cb->next)
892 { 854 {
855
893 pd->called_loop_counter++;//avi debug 856 pd->called_loop_counter++;//avi debug
894 if (!cb->delete_me) 857 if (!cb->delete_me)
895 { 858 {
859
896 if (( !cb->items.item.desc->unfreezable) && 860 if (( !cb->items.item.desc->unfreezable) &&
897 (event_freeze_count || pd->event_freeze_count)) 861 (event_freeze_count || pd->event_freeze_count))
898 continue; 862 continue;