summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2015-05-12 15:25:13 +0900
committerThiep Ha <thiepha@gmail.com>2015-06-02 21:50:24 +0900
commitce7c09085e2103170180af3dcf1c3ddd0b607439 (patch)
treec058be81ca15ed28e331a3841c6917e6bacb3079
parentf18cd3796eb3b66a849faddde98ea9ebb91982b9 (diff)
CnP_DnD/Wl: replace strcmp with eina hash function
Replace for loop and strcmp by eina hash function.
-rw-r--r--src/lib/elm_cnp.c165
1 files changed, 65 insertions, 100 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index b4453ad56..513d59f3d 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -2566,13 +2566,9 @@ _wl_targets_converter(char *target, Wl_Cnp_Selection *sel EINA_UNUSED, void *dat
2566 } 2566 }
2567 else 2567 else
2568 { 2568 {
2569 for (i = 0; i < CNP_N_ATOMS; i++) 2569 Cnp_Atom *atom = eina_hash_find(_types_hash, target);
2570 { 2570 if (atom)
2571 if (!strcmp(target, _atoms[i].name)) 2571 formats = atom->formats;
2572 {
2573 formats = _atoms[i].formats;
2574 }
2575 }
2576 } 2572 }
2577 /* Only provide formats which selection owner can send */ 2573 /* Only provide formats which selection owner can send */
2578 for (i = 0; i < CNP_N_ATOMS; i++) 2574 for (i = 0; i < CNP_N_ATOMS; i++)
@@ -2611,15 +2607,11 @@ _wl_general_converter(char *target, Wl_Cnp_Selection *sel EINA_UNUSED, void *dat
2611{ 2607{
2612 cnp_debug("in\n"); 2608 cnp_debug("in\n");
2613 Elm_Sel_Format formats = ELM_SEL_FORMAT_NONE; 2609 Elm_Sel_Format formats = ELM_SEL_FORMAT_NONE;
2614 int i = 0; 2610 Cnp_Atom *atom = NULL;
2615 for (i = 0; i < CNP_N_ATOMS; i++) 2611
2616 { 2612 atom = eina_hash_find(_types_hash, target);
2617 if (!strcmp(target, _atoms[i].name)) 2613 if (atom)
2618 { 2614 formats = atom->formats;
2619 formats = _atoms[i].formats;
2620 break;
2621 }
2622 }
2623 if (formats == ELM_SEL_FORMAT_NONE) 2615 if (formats == ELM_SEL_FORMAT_NONE)
2624 { 2616 {
2625 if (data_ret) 2617 if (data_ret)
@@ -2652,17 +2644,12 @@ static Eina_Bool
2652_wl_text_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret) 2644_wl_text_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret)
2653{ 2645{
2654 cnp_debug("in\n"); 2646 cnp_debug("in\n");
2655 int i = 0;
2656 Elm_Sel_Format formats = ELM_SEL_FORMAT_NONE; 2647 Elm_Sel_Format formats = ELM_SEL_FORMAT_NONE;
2648 Cnp_Atom *atom = NULL;
2657 2649
2658 for (i = 0; i < CNP_N_ATOMS; i++) 2650 atom = eina_hash_find(_types_hash, target);
2659 { 2651 if (atom)
2660 if (!strcmp(target, _atoms[i].name)) 2652 formats = atom->formats;
2661 {
2662 formats = _atoms[i].formats;
2663 break;
2664 }
2665 }
2666 if (formats == ELM_SEL_FORMAT_NONE) 2653 if (formats == ELM_SEL_FORMAT_NONE)
2667 { 2654 {
2668 if (data_ret) 2655 if (data_ret)
@@ -2791,29 +2778,24 @@ _wl_notify_handler_targets(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_
2791 if (!ev) return EINA_FALSE; 2778 if (!ev) return EINA_FALSE;
2792 char *data = ev->data; 2779 char *data = ev->data;
2793 int len = ev->len; 2780 int len = ev->len;
2794 int count = 0; 2781 int count = 0, i = 0;
2795 int i = 0, j = 0;
2796 char **data_arr = NULL; 2782 char **data_arr = NULL;
2783 Cnp_Atom *atom = NULL;
2797 2784
2798 _wl_selection_parser(data, len, &data_arr, &count); 2785 _wl_selection_parser(data, len, &data_arr, &count);
2799 for (i = 0; i < CNP_N_ATOMS; i++) 2786 for (i = 0; i < count; i++)
2800 { 2787 {
2801 Eina_Bool found = EINA_FALSE; 2788 atom = eina_hash_find(_types_hash, data_arr[i]);
2802 for (j = 2; j < count; j++) 2789 if (atom && (atom->formats != ELM_SEL_FORMAT_TARGETS))
2803 { 2790 {
2804 if (!strcmp(_atoms[i].name, data_arr[j])) 2791 cnp_debug("Match found: %s\n", atom->name);
2805 { 2792 sel->requestfinished = EINA_FALSE;
2806 printf("\n%d: Match found: %s\n", __LINE__, _atoms[i].name); 2793 /* Since we cannot call ecore_wl_dnd_drag_get in here (it causes
2807 sel->requestfinished = EINA_FALSE; 2794 ecore callbacks circular dependency and makes drag_send cannot
2808 /* Since we cannot call ecore_wl_dnd_drag_get in here (it causes 2795 be called), we use ecore_timer to call it */
2809 ecore callbacks circular dependency and makes drag_send cannot 2796 ecore_timer_add(0.001, _wl_dnd_drag_get_timer_cb, atom->name);
2810 be called), we use ecore_timer to call it */ 2797 break;
2811 ecore_timer_add(0.001, _wl_dnd_drag_get_timer_cb, _atoms[i].name);
2812 found = EINA_TRUE;
2813 break;
2814 }
2815 } 2798 }
2816 if (found) break;
2817 } 2799 }
2818 free(data_arr); 2800 free(data_arr);
2819 return EINA_TRUE; 2801 return EINA_TRUE;
@@ -3422,7 +3404,7 @@ _wl_selection_send(void *data, int type EINA_UNUSED, void *event)
3422 Ecore_Wl_Event_Data_Source_Send *ev; 3404 Ecore_Wl_Event_Data_Source_Send *ev;
3423 void *data_ret = NULL; 3405 void *data_ret = NULL;
3424 int len_ret = 0; 3406 int len_ret = 0;
3425 int i = 0; 3407 Cnp_Atom *atom = NULL;
3426 3408
3427 _wl_elm_cnp_init(); 3409 _wl_elm_cnp_init();
3428 3410
@@ -3430,26 +3412,23 @@ _wl_selection_send(void *data, int type EINA_UNUSED, void *event)
3430 ev = event; 3412 ev = event;
3431 sel = data; 3413 sel = data;
3432 3414
3433 for (i = 0; i < CNP_N_ATOMS; i++) 3415 atom = eina_hash_find(_types_hash, ev->type);
3416 if (atom)
3434 { 3417 {
3435 if (!strcmp(_atoms[i].name, ev->type)) 3418 cnp_debug("Found a type: %s\n", atom->name);
3419 Dropable *drop;
3420 eo_do(sel->requestwidget, drop = eo_key_data_get("__elm_dropable"));
3421 if (drop)
3422 drop->last.type = atom->name;
3423 if (atom->wl_converter)
3436 { 3424 {
3437 cnp_debug("Found a type: %s\n", _atoms[i].name); 3425 atom->wl_converter(ev->type, sel, sel->selbuf,
3438 Dropable *drop; 3426 sel->buflen, &data_ret, &len_ret);
3439 eo_do(sel->requestwidget, drop = eo_key_data_get("__elm_dropable")); 3427 }
3440 if (drop) 3428 else
3441 drop->last.type = _atoms[i].name; 3429 {
3442 if (_atoms[i].wl_converter) 3430 data_ret = strdup(sel->selbuf);
3443 { 3431 len_ret = sel->buflen;
3444 _atoms[i].wl_converter(ev->type, sel, sel->selbuf,
3445 sel->buflen, &data_ret, &len_ret);
3446 }
3447 else
3448 {
3449 data_ret = strdup(sel->selbuf);
3450 len_ret = sel->buflen;
3451 }
3452 break;
3453 } 3432 }
3454 } 3433 }
3455 3434
@@ -3486,47 +3465,37 @@ _wl_selection_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_R
3486 { 3465 {
3487 char *data = ev->data; 3466 char *data = ev->data;
3488 int len = ev->len; 3467 int len = ev->len;
3489 int count = 0; 3468 int count = 0, i = 0;
3490 int i = 0, j = 0;
3491 char **data_arr = NULL; 3469 char **data_arr = NULL;
3492 3470
3493 _wl_selection_parser(data, len, &data_arr, &count); 3471 _wl_selection_parser(data, len, &data_arr, &count);
3494 for (i = 2; i < CNP_N_ATOMS; i++) 3472 for (i = 0; i < count; i++)
3495 { 3473 {
3496 if ((sel->requestformat & _atoms[i].formats) && 3474 Cnp_Atom *atom = eina_hash_find(_types_hash, data_arr[i]);
3497 _atoms[i].wl_notify) 3475 if (atom && atom->wl_notify &&
3476 (atom->formats != ELM_SEL_FORMAT_TARGETS) &&
3477 (sel->requestformat & atom->formats))
3498 { 3478 {
3499 for (j = 0; j < count; j++) 3479 cnp_debug("Request new type: %s\n", atom->name);
3500 { 3480 sel->requesttype = atom->name;
3501 if (!strcmp(_atoms[i].name, data_arr[j])) 3481 sel->requestfinished = EINA_FALSE;
3502 { 3482 /* Since we cannot call ecore_wl_dnd_selection_get
3503 cnp_debug("Request new type: %s\n", _atoms[i].name); 3483 in here (it causes ecore callbacks circular
3504 sel->requesttype = _atoms[i].name; 3484 dependency and makes data send cannot
3505 sel->requestfinished = EINA_FALSE; 3485 be called), we use ecore_timer to call it */
3506 /* Since we cannot call ecore_wl_dnd_selection_get 3486 ecore_timer_add(0.001, _wl_selection_get_timer_cb,
3507 in here (it causes ecore callbacks circular 3487 atom->name);
3508 dependency and makes data send cannot 3488 return;
3509 be called), we use ecore_timer to call it */
3510 ecore_timer_add(0.001, _wl_selection_get_timer_cb,
3511 _atoms[i].name);
3512 return;
3513 }
3514 }
3515 } 3489 }
3516 } 3490 }
3517 } 3491 }
3518 else 3492 else
3519 { 3493 {
3520 int i = 0; 3494 Cnp_Atom *atom = eina_hash_find(_types_hash, sel->requesttype);
3521 for (i = 0; i < CNP_N_ATOMS; i++) 3495 if (atom && atom->wl_notify)
3522 { 3496 {
3523 if ((!strcmp(sel->requesttype, _atoms[i].name)) && 3497 cnp_debug("Call notify for: %s\n", atom->name);
3524 _atoms[i].wl_notify) 3498 atom->wl_notify(sel, ev);
3525 {
3526 cnp_debug("Call notify for: %s\n", _atoms[i].name);
3527 _atoms[i].wl_notify(sel, ev);
3528 return;
3529 }
3530 } 3499 }
3531 } 3500 }
3532} 3501}
@@ -4070,16 +4039,12 @@ _wl_dropable_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Re
4070 { 4039 {
4071 if (cbs->types && drop->last.format) 4040 if (cbs->types && drop->last.format)
4072 { 4041 {
4073 int i = 0; 4042 Cnp_Atom *atom = eina_hash_find(_types_hash, drop->last.type);
4074 for (i = 0; i < CNP_N_ATOMS; i++) 4043 if (atom && atom->wl_notify)
4075 { 4044 {
4076 if ((!strcmp(_atoms[i].name, drop->last.type)) 4045 cnp_debug("call notify: %s\n", drop->last.type);
4077 && _atoms[i].wl_notify) 4046 atom->wl_notify(sel, ev);
4078 { 4047 return;
4079 cnp_debug("call notify: %s\n", drop->last.type);
4080 _atoms[i].wl_notify(sel, ev);
4081 return;
4082 }
4083 } 4048 }
4084 } 4049 }
4085 } 4050 }