sbool_t sm_is_insert(sm_t **m, const sint_t k, const ss_t *v) { ASSERT_RETURN_IF(!m, S_FALSE); struct SMapIS n; n.x.k = k; n.v = ss_dup(v); return st_insert((st_t **)m, (const stn_t *)&n); }
void sso_dupa(srt_stringo *s) { switch (s->t) { case OptStr_I: s->k.i.s = ss_dup(s->k.i.s); break; case OptStr_DI: case OptStr_ID: s->kv.di.si = ss_dup(s->kv.di.si); break; case OptStr_II: s->kv.ii.s1 = ss_dup(s->kv.ii.s1); s->kv.ii.s2 = ss_dup(s->kv.ii.s2); break; default: /* cases not using dynamic memory */ break; } }
S_INLINE void sso1_set0(srt_stringo1 *so, const srt_string *s, srt_string *s0) { size_t ss; if (!so) return; if (!s) s = ss_void; ss = ss_size(s); if (ss <= OptStrMaxSize) { srt_string *s_out = (srt_string *)so->d.s_raw; ss_alloc_into_ext_buf(s_out, OptStrMaxSize); so->t = OptStr_D; ss_cpy(&s_out, s); } else { so->t = OptStr_I; if (s0) { so->i.s = s0; s0 = NULL; ss_cpy(&so->i.s, s); } else so->i.s = ss_dup(s); } ss_free(&s0); }
S_INLINE void sso_set0(srt_stringo *so, const srt_string *s1, const srt_string *s2, srt_string *sa, srt_string *sb) { size_t s1s, s2s; srt_string *so1, *so2; if (!so) return; if (!s1) s1 = ss_void; if (!s2) s2 = ss_void; s1s = ss_size(s1); s2s = ss_size(s2); if (s1s + s2s <= OptStr_MaxSize_DD) { so1 = (srt_string *)so->kv.di.s_raw; ss_alloc_into_ext_buf(so1, OptStr_MaxSize_DI); ss_cpy(&so1, s1); so->t = OptStr_DD; so2 = (srt_string *)sso_get_s2(so); ss_alloc_into_ext_buf(so2, OptStr_MaxSize_DI - s1s); ss_cpy(&so2, s2); } else if (s1s <= OptStr_MaxSize_DI) { so1 = (srt_string *)so->kv.di.s_raw; ss_alloc_into_ext_buf(so1, OptStr_MaxSize_DI); ss_cpy(&so1, s1); if (sa || sb) { if (sa) { so->kv.di.si = sa; sa = NULL; } else { so->kv.di.si = sb; sb = NULL; } ss_cpy(&so->kv.di.si, s2); } else so->kv.di.si = ss_dup(s2); so->t = OptStr_DI; } else if (s2s <= OptStr_MaxSize_DI) { if (sa || sb) { if (sa) { so->kv.di.si = sa; sa = NULL; } else { so->kv.di.si = sb; sb = NULL; } ss_cpy(&so->kv.di.si, s1); } else so->kv.di.si = ss_dup(s1); so2 = (srt_string *)so->kv.di.s_raw; ss_alloc_into_ext_buf(so2, OptStr_MaxSize_DI); ss_cpy(&so2, s2); so->t = OptStr_ID; } else { if (sa) { so->kv.ii.s1 = sa; sa = NULL; ss_cpy(&so->kv.ii.s1, s1); } else so->kv.ii.s1 = ss_dup(s1); if (sb) { so->kv.ii.s2 = sb; sb = NULL; ss_cpy(&so->kv.ii.s2, s2); } else so->kv.ii.s2 = ss_dup(s2); so->t = OptStr_II; } ss_free(&sa); ss_free(&sb); }
void sso_dupa1(srt_stringo1 *s) { if (s->t == OptStr_I) s->i.s = ss_dup(s->i.s); }