Skip to content

Commit

Permalink
kernel: remove MakeImmutableString
Browse files Browse the repository at this point in the history
This was simply an alias for MakeImmutableNoRecurse, and calling
it was a very minor (mostly: pointless) optimization compared to
calling the more generic MakeImmutable.

But crucially, the name was rather misleading, in particular when
compared to MakeImmString.

So, let's avoid some potential confusion (and the resulting source
of bugs) with a teeny weeny de-optimization (that won't even be
noticeable in practice).
  • Loading branch information
fingolfin committed Jun 5, 2019
1 parent f2b0cc9 commit ddfb57a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Obj GET_FILENAME_BODY(Obj body)
void SET_FILENAME_BODY(Obj body, Obj val)
{
GAP_ASSERT(IS_STRING_REP(val));
MakeImmutableString(val);
MakeImmutable(val);
BODY_HEADER(body)->filename_or_id = val;
}

Expand Down Expand Up @@ -220,7 +220,7 @@ Obj GET_LOCATION_BODY(Obj body)
void SET_LOCATION_BODY(Obj body, Obj val)
{
GAP_ASSERT(IS_STRING_REP(val));
MakeImmutableString(val);
MakeImmutable(val);
BODY_HEADER(body)->startline_or_location = val;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gvars.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void AssGVarWithoutReadOnlyCheck(UInt gvar, Obj val)
#endif
if ( val != 0 && TNUM_OBJ(val) == T_FUNCTION && NAME_FUNC(val) == 0 ) {
onam = CopyToStringRep(NameGVar(gvar));
MakeImmutableString(onam);
MakeImmutable(onam);
SET_NAME_FUNC(val, onam);
CHANGED_BAG(val);
}
Expand Down
2 changes: 1 addition & 1 deletion src/hpc/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static Obj MakeImmString2(const Char * cstr1, const Char * cstr2)
result = NEW_STRING(len1 + len2);
memcpy(CSTR_STRING(result), cstr1, len1);
memcpy(CSTR_STRING(result) + len1, cstr2, len2);
MakeImmutableString(result);
MakeImmutableNoRecurse(result);
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/opers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2605,7 +2605,7 @@ static Obj WRAP_NAME(Obj name, const char *addon)
ptr += name_len;
*ptr++ = ')';
*ptr = 0;
MakeImmutableString(fname);
MakeImmutable(fname);
return fname;
}

Expand All @@ -2622,7 +2622,7 @@ static Obj PREFIX_NAME(Obj name, const char *prefix)
memcpy( ptr, CONST_CSTR_STRING(name), name_len );
ptr += name_len;
*ptr = 0;
MakeImmutableString(fname);
MakeImmutable(fname);
return fname;
}

Expand Down
8 changes: 4 additions & 4 deletions src/stringobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ Obj ImmutableString(Obj string)
{
if (!IS_STRING_REP(string) || IS_MUTABLE_OBJ(string)) {
string = CopyToStringRep(string);
MakeImmutableString(string);
MakeImmutableNoRecurse(string);
}
return string;
}
Expand Down Expand Up @@ -2116,9 +2116,9 @@ static Int InitKernel (
UnbListFuncs [ t1 ] = UnbString;
}

MakeImmutableObjFuncs[ T_STRING ] = MakeImmutableString;
MakeImmutableObjFuncs[ T_STRING_SSORT ] = MakeImmutableString;
MakeImmutableObjFuncs[ T_STRING_NSORT ] = MakeImmutableString;
MakeImmutableObjFuncs[ T_STRING ] = MakeImmutableNoRecurse;
MakeImmutableObjFuncs[ T_STRING_SSORT ] = MakeImmutableNoRecurse;
MakeImmutableObjFuncs[ T_STRING_NSORT ] = MakeImmutableNoRecurse;

/* return success */
return 0;
Expand Down
14 changes: 2 additions & 12 deletions src/stringobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,6 @@ void ConvString(Obj string);
Int IsStringConv(Obj obj);


/****************************************************************************
**
*F MakeImmutableString( <str> ) . . . . . . make a string immutable in place
*/
EXPORT_INLINE void MakeImmutableString(Obj str)
{
MakeImmutableNoRecurse(str);
}


// Functions to create mutable and immutable GAP strings from C strings.
// MakeString and MakeImmString are inlineable so 'strlen' can be optimised
// away for constant strings.
Expand All @@ -354,14 +344,14 @@ EXPORT_INLINE Obj MakeString(const char * cstr)
EXPORT_INLINE Obj MakeImmString(const char * cstr)
{
Obj result = MakeString(cstr);
MakeImmutableString(result);
MakeImmutableNoRecurse(result);
return result;
}

EXPORT_INLINE Obj MakeImmStringWithLen(const char * buf, size_t len)
{
Obj result = MakeStringWithLen(buf, len);
MakeImmutableString(result);
MakeImmutableNoRecurse(result);
return result;
}

Expand Down

0 comments on commit ddfb57a

Please sign in to comment.