spa: add spa_pod_memcmp

Add a helper to memcmp two pods and use it in some places.
This commit is contained in:
Wim Taymans 2025-11-13 18:13:02 +01:00
parent b9a895f825
commit 18ff08243b
3 changed files with 11 additions and 10 deletions

View file

@ -11,6 +11,7 @@
#include <spa/pod/builder.h> #include <spa/pod/builder.h>
#include <spa/pod/iter.h> #include <spa/pod/iter.h>
#include <spa/pod/parser.h> #include <spa/pod/parser.h>
#include <spa/pod/compare.h>
#include <spa/param/tag.h> #include <spa/param/tag.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -33,8 +34,7 @@ extern "C" {
SPA_API_TAG_UTILS int SPA_API_TAG_UTILS int
spa_tag_compare(const struct spa_pod *a, const struct spa_pod *b) spa_tag_compare(const struct spa_pod *a, const struct spa_pod *b)
{ {
return ((a == b) || (a && b && SPA_POD_SIZE(a) == SPA_POD_SIZE(b) && return spa_pod_memcmp(a, b);
memcmp(a, b, SPA_POD_SIZE(b)) == 0)) ? 0 : 1;
} }
SPA_API_TAG_UTILS int SPA_API_TAG_UTILS int

View file

@ -80,6 +80,13 @@ SPA_API_POD_COMPARE int spa_pod_compare_value(uint32_t type, const void *r1, con
return 0; return 0;
} }
SPA_API_POD_COMPARE int spa_pod_memcmp(const struct spa_pod *a,
const struct spa_pod *b)
{
return ((a == b) || (a && b && SPA_POD_SIZE(a) == SPA_POD_SIZE(b) &&
memcmp(a, b, SPA_POD_SIZE(b)) == 0)) ? 0 : 1;
}
SPA_API_POD_COMPARE int spa_pod_compare(const struct spa_pod *pod1, SPA_API_POD_COMPARE int spa_pod_compare(const struct spa_pod *pod1,
const struct spa_pod *pod2) const struct spa_pod *pod2)
{ {
@ -149,12 +156,8 @@ SPA_API_POD_COMPARE int spa_pod_compare(const struct spa_pod *pod1,
break; break;
} }
case SPA_TYPE_Array: case SPA_TYPE_Array:
{ res = spa_pod_memcmp(pod1, pod2);
if (pod1->size != pod2->size)
return -EINVAL;
res = memcmp(SPA_POD_BODY(pod1), SPA_POD_BODY(pod2), pod2->size);
break; break;
}
default: default:
if (pod1->size != pod2->size) if (pod1->size != pod2->size)
return -EINVAL; return -EINVAL;

View file

@ -339,9 +339,7 @@ SPA_API_POD_FILTER int spa_pod_filter_part(struct spa_pod_builder *b,
default: default:
if (pf != NULL) { if (pf != NULL) {
if (pp->size != pf->size) if (spa_pod_memcmp(pp, pf) != 0)
return -EINVAL;
if (memcmp(pp, pf, pp->size) != 0)
return -EINVAL; return -EINVAL;
do_advance = true; do_advance = true;
} }