summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-08-02 15:27:20 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-10-28 15:47:13 +0900
commite95bd7755eada7a123cd3e8c560dbe72a297c837 (patch)
treefeac431b03330728d19f6a6f7b351a4c7ed494ab /src/bin
parentf5fee255de5a2e9f33c2d2f5b87b9ba02fd65922 (diff)
evas/cserve2: Add binary search in server side
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/evas/evas_cserve2_index.c60
1 files changed, 45 insertions, 15 deletions
diff --git a/src/bin/evas/evas_cserve2_index.c b/src/bin/evas/evas_cserve2_index.c
index 6563872f5b..66b50a4095 100644
--- a/src/bin/evas/evas_cserve2_index.c
+++ b/src/bin/evas/evas_cserve2_index.c
@@ -509,21 +509,51 @@ _shared_index_entry_new(Shared_Index *si)
509} 509}
510 510
511static Index_Entry * 511static Index_Entry *
512_shared_index_entry_find(Shared_Index *si, int id) 512_shared_index_entry_get_by_id(Shared_Index *si, unsigned int id)
513{ 513{
514 int k, count; 514 Index_Entry *obj;
515 const char *base;
516 int low = 0, high, start_high, elemsize;
517 int cur;
515 518
516 if (!si) return NULL; 519 if (!si || !si->sa || !id)
517 count = cserve2_shared_array_count_get(si->sa); 520 return NULL;
521
522 // FIXME: HACK (consider all arrays always sorted by id)
523 high = si->sa->header->emptyidx; // Should be si->sa->header->sortedidx
524
525 if (high > si->sa->header->count)
526 high = si->sa->header->count;
527
528 base = si->sa->ds->data + sizeof(Shared_Array_Header);
529 elemsize = si->sa->header->elemsize;
530
531 // Binary search
532 start_high = high;
533 while(high != low)
534 {
535 cur = low + ((high - low) / 2);
536 obj = (Index_Entry *) (base + (elemsize * cur));
537 if (!obj)
538 return NULL;
539 if (obj->id == id)
540 return obj;
541 if (obj->id < id)
542 low = cur + 1;
543 else
544 high = cur;
545 }
518 546
519 // FIXME: Linear search O(n) 547 // Linear search
520 for (k = 0; k < count; k++) 548 for (cur = start_high; cur < si->sa->header->count; cur++)
521 { 549 {
522 Index_Entry *ie; 550 obj = (Index_Entry *) (base + (elemsize * cur));
523 ie = cserve2_shared_array_item_data_get(si->sa, k); 551 if (!obj)
524 if (!ie) break; 552 return NULL;
525 if (ie->id == id) 553 if (!obj->id)
526 return ie; 554 return NULL;
555 if (obj->id == id)
556 return obj;
527 } 557 }
528 558
529 return NULL; 559 return NULL;
@@ -709,7 +739,7 @@ cserve2_shared_mempool_buffer_ref(Shared_Mempool *sm, int bufferid)
709 Index_Entry *ie; 739 Index_Entry *ie;
710 740
711 if (!sm) return -1; 741 if (!sm) return -1;
712 ie = _shared_index_entry_find(sm->index, bufferid); 742 ie = _shared_index_entry_get_by_id(sm->index, bufferid);
713 if (!ie) return -1; 743 if (!ie) return -1;
714 744
715 if (!ie->refcount) 745 if (!ie->refcount)
@@ -742,7 +772,7 @@ _shared_mempool_buffer_del(Shared_Mempool *sm, int bufferid)
742 772
743 if (!sm || !bufferid) return EINA_FALSE; 773 if (!sm || !bufferid) return EINA_FALSE;
744 774
745 ie = _shared_index_entry_find(sm->index, bufferid); 775 ie = _shared_index_entry_get_by_id(sm->index, bufferid);
746 if (!ie || ie->refcount <= 0) 776 if (!ie || ie->refcount <= 0)
747 { 777 {
748 CRIT("Tried to delete invalid buffer or with refcount 0"); 778 CRIT("Tried to delete invalid buffer or with refcount 0");
@@ -778,7 +808,7 @@ cserve2_shared_mempool_buffer_get(Shared_Mempool *sm, int bufferid)
778 char *data; 808 char *data;
779 809
780 if (!sm) return NULL; 810 if (!sm) return NULL;
781 ie = _shared_index_entry_find(sm->index, bufferid); 811 ie = _shared_index_entry_get_by_id(sm->index, bufferid);
782 if (!ie || ie->refcount <= 0) 812 if (!ie || ie->refcount <= 0)
783 { 813 {
784 CRIT("Tried to access invalid buffer or with refcount 0"); 814 CRIT("Tried to access invalid buffer or with refcount 0");
@@ -823,7 +853,7 @@ cserve2_shared_string_add(const char *str)
823 id = (int) (intptr_t) eina_hash_find(_string_entries, str); 853 id = (int) (intptr_t) eina_hash_find(_string_entries, str);
824 if (id > 0) 854 if (id > 0)
825 { 855 {
826 ie = _shared_index_entry_find(_string_mempool->index, id); 856 ie = _shared_index_entry_get_by_id(_string_mempool->index, id);
827 if (!ie || ie->refcount <= 0) 857 if (!ie || ie->refcount <= 0)
828 { 858 {
829 CRIT("String found in hash but not in mempool!"); 859 CRIT("String found in hash but not in mempool!");