get_one_sexp() is better now;

master^2
Alexander Vdolainen 5 years ago
parent fbb4a81701
commit e0cd74ac99

@ -60,10 +60,28 @@ void destroy_cstrwrap(sexp_cstrwrap_t *csw)
return;
}
static inline void __rnc_buf(sexp_cstrwrap_t *wr)
{
int sbuf_size = 0;
if(wr->sln - wr->cnt >= CSTRBUFSIZ) sbuf_size = CSTRBUFSIZ;
else sbuf_size = wr->sln - wr->cnt;
/*
* FIXME: is it ugly to copy?
* TODO: way to optimize is to modify a source string
* temproary - it's a way more worse
*/
memcpy(wr->buf, wr->seval + wr->cnt, sbuf_size);
wr->cnt += sbuf_size;
wr->rl = sbuf_size;
return;
}
sexp_t *get_one_sexp(sexp_cstrwrap_t *wr)
{
sexp_t *sx = NULL;
int sbuf_size = 0;
if(!wr) return NULL;
@ -87,13 +105,7 @@ sexp_t *get_one_sexp(sexp_cstrwrap_t *wr)
return NULL; /* we're done here */
}
if(wr->sln - wr->cnt >= CSTRBUFSIZ) sbuf_size = CSTRBUFSIZ;
else sbuf_size = wr->sln - wr->cnt;
/* FIXME: it's ugly to copy TODO: optimize it there */
memcpy(wr->buf, wr->seval + wr->cnt, sbuf_size);
wr->cnt += sbuf_size;
wr->rl = sbuf_size;
__rnc_buf(wr);
}
wr->cc = cparse_sexp(wr->buf, wr->rl, wr->cc);
@ -105,20 +117,13 @@ sexp_t *get_one_sexp(sexp_cstrwrap_t *wr)
return NULL;
}
/* TODO: FIXME: remove copy-n-paste */
/* check for EOB */
if(wr->sln == wr->cnt) {
sexp_errno = SEXP_ERR_IO_EMPTY;
return NULL; /* we're done here, s expression didn't finished */
}
if(wr->sln - wr->cnt >= CSTRBUFSIZ) sbuf_size = CSTRBUFSIZ;
else sbuf_size = wr->sln - wr->cnt;
/* FIXME: it's ugly to copy TODO: optimize it there */
memcpy(wr->buf, wr->seval + wr->cnt, sbuf_size);
wr->cnt += sbuf_size;
wr->rl = sbuf_size;
__rnc_buf(wr);
wr->cc = cparse_sexp(wr->buf, wr->rl, wr->cc);
wr->rl = 0;

Loading…
Cancel
Save