aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--VERSION2
-rw-r--r--props.h82
-rw-r--r--test/props.ttl2
3 files changed, 37 insertions, 49 deletions
diff --git a/VERSION b/VERSION
index 496a825..9c178d3 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.91
+0.1.95
diff --git a/props.h b/props.h
index 463e123..d8beda2 100644
--- a/props.h
+++ b/props.h
@@ -120,12 +120,12 @@ struct _props_t {
uint32_t max_size;
unsigned nimpls;
- props_impl_t impls [0];
+ props_impl_t impls [1];
};
#define PROPS_T(PROPS, MAX_NIMPLS) \
props_t (PROPS); \
- props_impl_t _impls [(MAX_NIMPLS)]
+ props_impl_t _impls [(MAX_NIMPLS-1)]
// rt-safe
static inline int
@@ -223,52 +223,40 @@ _props_restoring_set(props_t *props)
atomic_store_explicit(&props->restoring, true, memory_order_release);
}
-static inline void
-_props_qsort(props_impl_t *A, int n)
+static inline props_impl_t *
+_props_impl_get(props_t *props, LV2_URID property)
{
- if(n < 2)
- return;
-
- const props_impl_t *p = A;
-
- int i = -1;
- int j = n;
-
- while(true)
+ for(unsigned i = 0, idx = (property + i) % props->nimpls;
+ i < props->nimpls;
+ i++, idx = (property + i) % props->nimpls)
{
- do {
- i += 1;
- } while(A[i].property < p->property);
+ props_impl_t *impl = &props->impls[idx];
- do {
- j -= 1;
- } while(A[j].property > p->property);
-
- if(i >= j)
- break;
-
- const props_impl_t tmp = A[i];
- A[i] = A[j];
- A[j] = tmp;
+ if(impl->property == property)
+ {
+ return impl;
+ }
}
- _props_qsort(A, j + 1);
- _props_qsort(A + j + 1, n - j - 1);
+ return NULL;
}
static inline props_impl_t *
-_props_bsearch(props_t *props, LV2_URID property)
+_props_impl_add(props_t *props, LV2_URID property)
{
- props_impl_t *base = props->impls;
-
- for(int N = props->nimpls, half; N > 1; N -= half)
+ for(unsigned i = 0, idx = (property + i) % props->nimpls;
+ i < props->nimpls;
+ i++, idx = (property + i) % props->nimpls)
{
- half = N/2;
- props_impl_t *dst = &base[half];
- base = (dst->property > property) ? base : dst;
+ props_impl_t *impl = &props->impls[idx];
+
+ if(impl->property == 0)
+ {
+ return impl;
+ }
}
- return (base->property == property) ? base : NULL;
+ return NULL;
}
static inline LV2_Atom_Forge_Ref
@@ -417,7 +405,7 @@ static inline int
_props_impl_init(props_t *props, props_impl_t *impl, const props_def_t *def,
void *value_base, void *stash_base, LV2_URID_Map *map)
{
- if(!def->property || !def->type)
+ if(!impl || !def->property || !def->type)
return 0;
const LV2_URID type = map->map(map->handle, def->type);
@@ -536,14 +524,14 @@ props_init(props_t *props, const char *subject,
int status = 1;
for(unsigned i = 0; i < props->nimpls; i++)
{
- props_impl_t *impl = &props->impls[i];
+ const props_def_t *def = &defs[i];
+ const LV2_URID property = map->map(map->handle, def->property);
+ props_impl_t *impl = _props_impl_add(props, property);
status = status
- && _props_impl_init(props, impl, &defs[i], value_base, stash_base, map);
+ && _props_impl_init(props, impl, def, value_base, stash_base, map);
}
- _props_qsort(props->impls, props->nimpls);
-
return status;
}
@@ -624,7 +612,7 @@ props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
}
else if(property->atom.type == props->urid.atom_urid)
{
- props_impl_t *impl = _props_bsearch(props, property->body);
+ props_impl_t *impl = _props_impl_get(props, property->body);
if(impl)
{
@@ -680,7 +668,7 @@ props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
return 0;
}
- props_impl_t *impl = _props_bsearch(props, property->body);
+ props_impl_t *impl = _props_impl_get(props, property->body);
if(impl && (impl->access == props->urid.patch_writable) )
{
_props_impl_set(props, impl, value->type, value->size,
@@ -743,7 +731,7 @@ props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
const LV2_URID property = prop->key;
const LV2_Atom *value = &prop->value;
- props_impl_t *impl = _props_bsearch(props, property);
+ props_impl_t *impl = _props_impl_get(props, property);
if(impl && (impl->access == props->urid.patch_writable) )
{
_props_impl_set(props, impl, value->type, value->size,
@@ -770,7 +758,7 @@ static inline void
props_set(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
LV2_URID property, LV2_Atom_Forge_Ref *ref)
{
- props_impl_t *impl = _props_bsearch(props, property);
+ props_impl_t *impl = _props_impl_get(props, property);
if(impl)
{
@@ -784,7 +772,7 @@ props_set(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
static inline void
props_stash(props_t *props, LV2_URID property)
{
- props_impl_t *impl = _props_bsearch(props, property);
+ props_impl_t *impl = _props_impl_get(props, property);
if(impl)
_props_impl_stash(props, impl);
@@ -807,7 +795,7 @@ props_map(props_t *props, const char *uri)
static inline const char *
props_unmap(props_t *props, LV2_URID property)
{
- props_impl_t *impl = _props_bsearch(props, property);
+ props_impl_t *impl = _props_impl_get(props, property);
if(impl)
return impl->def->property;
diff --git a/test/props.ttl b/test/props.ttl
index 0ce45d6..b9456d6 100644
--- a/test/props.ttl
+++ b/test/props.ttl
@@ -147,6 +147,6 @@ props:test
props:statInt 4 ;
props:statFloat "0.4"^^xsd:float ;
props:statString "Hello world" ;
- props:statPath <props.ttl> ;
+ props:statPath <file://tmp/props.ttl> ;
props:statChunk "AQIDBAUGBw=="^^xsd:base64Binary ;
] .