Enlightenment CVS committal

Author  : tsauerbeck
Project : e17
Module  : libs/evas

Dir     : e17/libs/evas/src/lib/data


Modified Files:
        evas_list.c 


Log Message:
evas_list_nth_* improvements, step 2
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/evas/src/lib/data/evas_list.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- evas_list.c 31 Jan 2005 17:26:11 -0000      1.7
+++ evas_list.c 31 Jan 2005 17:44:30 -0000      1.8
@@ -1,3 +1,6 @@
+/*
+ * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
+ */
 #include "evas_common.h"
 #include "evas_private.h"
 #include "Evas.h"
@@ -698,12 +701,30 @@
 {
    int i;
    Evas_List *l;
-   
-   if (n < 0) return NULL;
-   for (i = 0, l = list; l; l = l->next, i++)
+
+   /* check for non-existing nodes */
+   if (n < 0 || n > list->count - 1) return NULL;
+
+   /* if the node is in the 2nd half of the list, search from the end
+    * else, search from the beginning.
+    */
+   if (n > list->count / 2)
      {
-       if (i == n) return l;
+       n = list->count - n - 1;
+
+       for (i = 0, l = list->last; l; l = l->prev, i++)
+         {
+            if (i == n) return l;
+         }
      }
+   else
+     {
+       for (i = 0, l = list; l; l = l->next, i++)
+         {
+            if (i == n) return l;
+         }
+     }
+
    return NULL;
 }
 




-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to