Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-11-16 16:02:18 +0300
committerCampbell Barton <ideasman42@gmail.com>2014-11-16 16:06:03 +0300
commit0e60accf2afa4fc69da99743bb64d82cb3e0fbc4 (patch)
tree7013c96248c881481287eb84f8de715f1f0563f2 /source
parent7d040d2a088ec425550da4242650f1ff75680e0d (diff)
BLI_listbase: Add BLI_listbase_count_ex (sets a limit)
This can be used to avoid redundant looping when we only want to know if a list is smaller then some size. also remove paranoid NULL check in list counting.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/BLI_listbase.h1
-rw-r--r--source/blender/blenlib/intern/listbase.c22
2 files changed, 16 insertions, 7 deletions
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index 543a662c5e5..2e01f743f9e 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -70,6 +70,7 @@ void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewl
void BLI_listbase_sort(struct ListBase *listbase, int (*cmp)(const void *, const void *)) ATTR_NONNULL(1, 2);
void BLI_listbase_sort_r(ListBase *listbase, void *thunk, int (*cmp)(void *, const void *, const void *)) ATTR_NONNULL(1, 3);
void BLI_freelist(struct ListBase *listbase) ATTR_NONNULL(1);
+int BLI_listbase_count_ex(const struct ListBase *listbase, const int count_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c
index cd2e343560f..ea33b9b1e3b 100644
--- a/source/blender/blenlib/intern/listbase.c
+++ b/source/blender/blenlib/intern/listbase.c
@@ -372,6 +372,17 @@ void BLI_freelistN(ListBase *listbase)
BLI_listbase_clear(listbase);
}
+int BLI_listbase_count_ex(const ListBase *listbase, const int count_max)
+{
+ Link *link;
+ int count = 0;
+
+ for (link = listbase->first; link && count != count_max; link = link->next) {
+ count++;
+ }
+
+ return count;
+}
/**
* Returns the number of elements in \a listbase.
@@ -380,14 +391,11 @@ int BLI_listbase_count(const ListBase *listbase)
{
Link *link;
int count = 0;
-
- if (listbase) {
- link = listbase->first;
- while (link) {
- count++;
- link = link->next;
- }
+
+ for (link = listbase->first; link; link = link->next) {
+ count++;
}
+
return count;
}