Skip to content

Commit

Permalink
kernel: make SET_/GET_ELM_STRING private
Browse files Browse the repository at this point in the history
These functions really are only useful for interfacing with the GAP
language; there seems to be no reason to use them on the kernel level,
ever -- at most perhaps in the compiler, but the compiler does not
handle strings differently from other lists.
  • Loading branch information
fingolfin committed Sep 23, 2018
1 parent 5ced3f7 commit 7076039
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
2 changes: 0 additions & 2 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ VoidFunc debug_func_pointers[] = {
#endif
(VoidFunc)GET_ELM_PREC,
(VoidFunc)GET_ELM_RANGE,
(VoidFunc)GET_ELM_STRING,
(VoidFunc)GET_INC_RANGE,
(VoidFunc)GET_LEN_RANGE,
(VoidFunc)GET_LEN_STRING,
Expand Down Expand Up @@ -205,7 +204,6 @@ VoidFunc debug_func_pointers[] = {
(VoidFunc)SET_DEN_RAT,
(VoidFunc)SET_ELM_PLIST,
(VoidFunc)SET_ELM_PREC,
(VoidFunc)SET_ELM_STRING,
(VoidFunc)SET_ENVI_FUNC,
(VoidFunc)SET_FEXS_FUNC,
(VoidFunc)SET_HDLR_FUNC,
Expand Down
44 changes: 40 additions & 4 deletions src/stringobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
**
** This package consists of three parts.
**
** The first part consists of the macros 'NEW_STRING', 'CHARS_STRING' (or
** 'CSTR_STRING'), 'GET_LEN_STRING', 'SET_LEN_STRING', 'GET_ELM_STRING',
** 'SET_ELM_STRING' and 'C_NEW_STRING'. These and the functions below
** use the detailed knowledge about the representation of strings.
** The first part consists of the functions 'NEW_STRING', 'CHARS_STRING' (or
** 'CSTR_STRING'), 'GET_LEN_STRING', 'SET_LEN_STRING', 'C_NEW_STRING' and
** more. These and the functions below use the detailed knowledge about the
** representation of strings.
**
** The second part consists of the functions 'LenString', 'ElmString',
** 'ElmsStrings', 'AssString', 'AsssString', PlainString',
Expand Down Expand Up @@ -793,6 +793,42 @@ Int IsbString (
}


/****************************************************************************
**
*F GET_ELM_STRING( <list>, <pos> ) . . . . . . select an element of a string
**
** 'GET_ELM_STRING' returns the <pos>-th element of the string <list>.
** <pos> must be a positive integer less than or equal to the length of
** <list>.
*/
static inline Obj GET_ELM_STRING(Obj list, Int pos)
{
GAP_ASSERT(IS_STRING_REP(list));
GAP_ASSERT(pos > 0);
GAP_ASSERT((UInt) pos <= GET_LEN_STRING(list));
UChar c = CHARS_STRING(list)[pos - 1];
return ObjsChar[c];
}


/****************************************************************************
**
*F SET_ELM_STRING( <list>, <pos>, <val> ) . . . . set a character of a string
**
** 'SET_ELM_STRING' sets the <pos>-th character of the string <list>.
** <val> must be a character and <list> stay a string after the assignment.
*/
static inline void SET_ELM_STRING(Obj list, Int pos, Obj val)
{
GAP_ASSERT(IS_STRING_REP(list));
GAP_ASSERT(pos > 0);
GAP_ASSERT((UInt) pos <= GET_LEN_STRING(list));
GAP_ASSERT(TNUM_OBJ(val) == T_CHAR);
UChar * ptr = CHARS_STRING(list) + (pos - 1);
*ptr = CHAR_VALUE(val);
}


/****************************************************************************
**
*F Elm0String(<list>,<pos>) . . . . . . . . . select an element of a string
Expand Down
37 changes: 1 addition & 36 deletions src/stringobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
**
** Strings in compact representation can be accessed and handled through
** the functions 'NEW_STRING', 'CHARS_STRING' (and 'CSTR_STRING'),
** 'GET_LEN_STRING', 'SET_LEN_STRING', 'GROW_STRING', 'GET_ELM_STRING'
** and 'SET_ELM_STRING'.
** 'GET_LEN_STRING', 'SET_LEN_STRING', 'GROW_STRING' and more.
*/

#ifndef GAP_STRINGOBJ_H
Expand Down Expand Up @@ -188,40 +187,6 @@ static inline void SHRINK_STRING(Obj list)
ResizeBag(list, SIZEBAG_STRINGLEN(GET_LEN_STRING((list))));
}

/****************************************************************************
**
*F GET_ELM_STRING( <list>, <pos> ) . . . . . . select an element of a string
**
** 'GET_ELM_STRING' returns the <pos>-th element of the string <list>.
** <pos> must be a positive integer less than or equal to the length of
** <list>.
*/
static inline Obj GET_ELM_STRING(Obj list, Int pos)
{
GAP_ASSERT(IS_STRING_REP(list));
GAP_ASSERT(pos > 0);
GAP_ASSERT((UInt) pos <= GET_LEN_STRING(list));
UChar c = CHARS_STRING(list)[pos - 1];
return ObjsChar[c];
}

/****************************************************************************
**
*F SET_ELM_STRING( <list>, <pos>, <val> ) . . . . set a character of a string
**
** 'SET_ELM_STRING' sets the <pos>-th character of the string <list>.
** <val> must be a character and <list> stay a string after the assignment.
*/
static inline void SET_ELM_STRING(Obj list, Int pos, Obj val)
{
GAP_ASSERT(IS_STRING_REP(list));
GAP_ASSERT(pos > 0);
GAP_ASSERT((UInt) pos <= GET_LEN_STRING(list));
GAP_ASSERT(TNUM_OBJ(val) == T_CHAR);
UChar * ptr = CHARS_STRING(list) + (pos - 1);
*ptr = CHAR_VALUE(val);
}

/****************************************************************************
**
*F COPY_CHARS( <str>, <charpnt>, <n> ) . . . copies <n> chars, starting
Expand Down

0 comments on commit 7076039

Please sign in to comment.