(mcview_get_byte_string): minor optimization.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2014-09-12 09:45:12 +04:00
parent 60e1a06c06
commit c20e96b4bc

View File

@ -151,19 +151,6 @@ mcview_get_ptr_file (mcview_t * view, off_t byte_index)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
char *
mcview_get_ptr_string (mcview_t * view, off_t byte_index)
{
#ifdef HAVE_ASSERT_H
assert (view->datasource == DS_STRING);
#endif
if (byte_index < (off_t) view->ds_string_len)
return (char *) (view->ds_string_data + byte_index);
return NULL;
}
/* --------------------------------------------------------------------------------------------- */
int int
mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * result) mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * result)
{ {
@ -237,21 +224,34 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
gboolean char *
mcview_get_byte_string (mcview_t * view, off_t byte_index, int *retval) mcview_get_ptr_string (mcview_t * view, off_t byte_index)
{ {
#ifdef HAVE_ASSERT_H #ifdef HAVE_ASSERT_H
assert (view->datasource == DS_STRING); assert (view->datasource == DS_STRING);
#endif #endif
if (byte_index < (off_t) view->ds_string_len) if (byte_index >= 0 && byte_index < (off_t) view->ds_string_len)
{ return (char *) (view->ds_string_data + byte_index);
if (retval) return NULL;
*retval = view->ds_string_data[byte_index]; }
return TRUE;
} /* --------------------------------------------------------------------------------------------- */
if (retval)
gboolean
mcview_get_byte_string (mcview_t * view, off_t byte_index, int *retval)
{
char *p;
if (retval != NULL)
*retval = -1; *retval = -1;
p = mcview_get_ptr_string (view, byte_index);
if (p == NULL)
return FALSE; return FALSE;
if (retval != NULL)
*retval = *p;
return TRUE;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */