Commit e0538e0d authored by Hanspeter Portner's avatar Hanspeter Portner

Squashed 'props.lv2/' changes from 56d6943..fca36e5

fca36e5 migrate brom bsearch to linear probing.
9cb9fce silence pedantic warnings.

git-subtree-dir: props.lv2
git-subtree-split: fca36e5ef63481463f4d27d14894e84ad4a2a811
parent 6da3b1ef
...@@ -120,12 +120,12 @@ struct _props_t { ...@@ -120,12 +120,12 @@ struct _props_t {
uint32_t max_size; uint32_t max_size;
unsigned nimpls; unsigned nimpls;
props_impl_t impls [0]; props_impl_t impls [1];
}; };
#define PROPS_T(PROPS, MAX_NIMPLS) \ #define PROPS_T(PROPS, MAX_NIMPLS) \
props_t (PROPS); \ props_t (PROPS); \
props_impl_t _impls [(MAX_NIMPLS)] props_impl_t _impls [(MAX_NIMPLS-1)]
// rt-safe // rt-safe
static inline int static inline int
...@@ -223,52 +223,40 @@ _props_restoring_set(props_t *props) ...@@ -223,52 +223,40 @@ _props_restoring_set(props_t *props)
atomic_store_explicit(&props->restoring, true, memory_order_release); atomic_store_explicit(&props->restoring, true, memory_order_release);
} }
static inline void static inline props_impl_t *
_props_qsort(props_impl_t *A, int n) _props_impl_get(props_t *props, LV2_URID property)
{ {
if(n < 2) for(unsigned i = 0, idx = (property + i) % props->nimpls;
return; i < props->nimpls;
i++, idx = (property + i) % props->nimpls)
const props_impl_t *p = A;
int i = -1;
int j = n;
while(true)
{ {
do { props_impl_t *impl = &props->impls[idx];
i += 1;
} while(A[i].property < p->property);
do { if(impl->property == property)
j -= 1; {
} while(A[j].property > p->property); return impl;
}
if(i >= j)
break;
const props_impl_t tmp = A[i];
A[i] = A[j];
A[j] = tmp;
} }
_props_qsort(A, j + 1); return NULL;
_props_qsort(A + j + 1, n - j - 1);
} }
static inline props_impl_t * 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(unsigned i = 0, idx = (property + i) % props->nimpls;
i < props->nimpls;
for(int N = props->nimpls, half; N > 1; N -= half) i++, idx = (property + i) % props->nimpls)
{ {
half = N/2; props_impl_t *impl = &props->impls[idx];
props_impl_t *dst = &base[half];
base = (dst->property > property) ? base : dst; if(impl->property == 0)
{
return impl;
}
} }
return (base->property == property) ? base : NULL; return NULL;
} }
static inline LV2_Atom_Forge_Ref static inline LV2_Atom_Forge_Ref
...@@ -417,7 +405,7 @@ static inline int ...@@ -417,7 +405,7 @@ static inline int
_props_impl_init(props_t *props, props_impl_t *impl, const props_def_t *def, _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) void *value_base, void *stash_base, LV2_URID_Map *map)
{ {
if(!def->property || !def->type) if(!impl || !def->property || !def->type)
return 0; return 0;
const LV2_URID type = map->map(map->handle, def->type); const LV2_URID type = map->map(map->handle, def->type);
...@@ -536,14 +524,14 @@ props_init(props_t *props, const char *subject, ...@@ -536,14 +524,14 @@ props_init(props_t *props, const char *subject,
int status = 1; int status = 1;
for(unsigned i = 0; i < props->nimpls; i++) 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 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; return status;
} }
...@@ -624,7 +612,7 @@ props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames, ...@@ -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) 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) if(impl)
{ {
...@@ -680,7 +668,7 @@ props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames, ...@@ -680,7 +668,7 @@ props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
return 0; 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) ) if(impl && (impl->access == props->urid.patch_writable) )
{ {
_props_impl_set(props, impl, value->type, value->size, _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, ...@@ -743,7 +731,7 @@ props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
const LV2_URID property = prop->key; const LV2_URID property = prop->key;
const LV2_Atom *value = &prop->value; 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) ) if(impl && (impl->access == props->urid.patch_writable) )
{ {
_props_impl_set(props, impl, value->type, value->size, _props_impl_set(props, impl, value->type, value->size,
...@@ -770,7 +758,7 @@ static inline void ...@@ -770,7 +758,7 @@ static inline void
props_set(props_t *props, LV2_Atom_Forge *forge, uint32_t frames, props_set(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
LV2_URID property, LV2_Atom_Forge_Ref *ref) 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) if(impl)
{ {
...@@ -784,7 +772,7 @@ props_set(props_t *props, LV2_Atom_Forge *forge, uint32_t frames, ...@@ -784,7 +772,7 @@ props_set(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
static inline void static inline void
props_stash(props_t *props, LV2_URID property) 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) if(impl)
_props_impl_stash(props, impl); _props_impl_stash(props, impl);
...@@ -807,7 +795,7 @@ props_map(props_t *props, const char *uri) ...@@ -807,7 +795,7 @@ props_map(props_t *props, const char *uri)
static inline const char * static inline const char *
props_unmap(props_t *props, LV2_URID property) 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) if(impl)
return impl->def->property; return impl->def->property;
......
...@@ -147,6 +147,6 @@ props:test ...@@ -147,6 +147,6 @@ props:test
props:statInt 4 ; props:statInt 4 ;
props:statFloat "0.4"^^xsd:float ; props:statFloat "0.4"^^xsd:float ;
props:statString "Hello world" ; props:statString "Hello world" ;
props:statPath <props.ttl> ; props:statPath <file://tmp/props.ttl> ;
props:statChunk "AQIDBAUGBw=="^^xsd:base64Binary ; props:statChunk "AQIDBAUGBw=="^^xsd:base64Binary ;
] . ] .
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment