Skip to content

Commit

Permalink
Intern more strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Cole committed Oct 15, 2023
1 parent a60c50e commit 35c7c43
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 132 deletions.
2 changes: 1 addition & 1 deletion YSI_Coding/y_hooks/y_hooks_impl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2398,7 +2398,7 @@ stock _yH@(compressedFormat, address, order = cellmin, &a = 0, &b = 0, &c = 0, &
// the stack the final parameter won't be the string we passed here, but
// `a` from the extra parameters above. But that's fine - either way it
// points to nothing.
return Hooks_RegisterNPSHook(compressedFormat, address, "", order);
return Hooks_RegisterNPSHook(compressedFormat, address, YSI_EMPTY, order);
}

stock _yH@(compressedFormat, address, order = cellmin, &a = 0, &b = 0, &c = 0, &d = 0, &e = 0, &f = 0, &g = 0) <>
Expand Down
17 changes: 7 additions & 10 deletions YSI_Coding/y_inline/y_inline_impl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ __COMPILER_CONST_STATIC INLINE_PATTERN_4 = _C<Cole>;
#define CALL@Inline_operatorMul%8() ((@Ik:0)*%8(0))
#define CALL@Inline_EBC__%8() Inline_EBC__%8(0,0)

static stock const
YSI_gscSpecifier_i[] = "i";

static stock Inline_TBC__(timerID)
{
// Destroy inlines with this owner.
Expand All @@ -298,7 +295,7 @@ stock Inline_EBC__(owner, tag)
return
++timerID,
//// Set a timer to kill this inline eventually.
YSI_SetTimerEx__(&Inline_TBC__, owner, false, YSI_gscSpecifier_i, timerID),
YSI_SetTimerEx__(&Inline_TBC__, owner, false, YSI_gcI, timerID),
(timerID | (0x1FF << 22)) & cellmax;
}
else
Expand Down Expand Up @@ -1230,7 +1227,7 @@ stock Function:GetRemoteFunction(const func[], const spec[], tag = 0)
mset(closure, _:E_INDIRECTION_HANDER, _:addressof (Callback_RemoteHandler_<x>));
mset(closure, _:E_INDIRECTION_CLAIM, _:addressof (Callback_Claim_));
mset(closure, _:E_INDIRECTION_RELEASE, _:addressof (Callback_Release_<tResolvedAlloc:>));
mset(closure, _:E_PUBLIC_CALL_TIMER, YSI_SetTimerEx__(&Inline_MaybeFree_<tAlloc:>, 0, false, YSI_gscSpecifier_i, _:closure));
mset(closure, _:E_PUBLIC_CALL_TIMER, YSI_SetTimerEx__(&Inline_MaybeFree_<tAlloc:>, 0, false, YSI_gcI, _:closure));
mset(closure, _:E_PUBLIC_CALL_FLAGS, e_INLINE_FLAG_PUBLIC);
mset(closure, _:E_INDIRECTION_METADATA, 0);
if (tag)
Expand Down Expand Up @@ -1288,7 +1285,7 @@ stock Function:GetLocalFunction(const func[], const spec[], tag = 0)
mset(closure, _:E_INDIRECTION_HANDER, _:addressof (Callback_LocalHandler_<x>));
mset(closure, _:E_INDIRECTION_CLAIM, _:addressof (Callback_Claim_));
mset(closure, _:E_INDIRECTION_RELEASE, _:addressof (Callback_Release_<tResolvedAlloc:>));
mset(closure, _:E_PUBLIC_CALL_TIMER, YSI_SetTimerEx__(&Inline_MaybeFree_<tAlloc:>, 0, false, YSI_gscSpecifier_i, _:closure));
mset(closure, _:E_PUBLIC_CALL_TIMER, YSI_SetTimerEx__(&Inline_MaybeFree_<tAlloc:>, 0, false, YSI_gcI, _:closure));
mset(closure, _:E_PUBLIC_CALL_FLAGS, e_INLINE_FLAG_PUBLIC);
mset(closure, _:E_INDIRECTION_METADATA, 0);
if (tag)
Expand Down Expand Up @@ -1407,7 +1404,7 @@ static stock Callback_InlineByName(const name[], tag)
mset(closure, _:E_INDIRECTION_HANDER, _:addressof (Callback_CallHandler_<x>));
mset(closure, _:E_INDIRECTION_CLAIM, _:addressof (Callback_Claim_));
mset(closure, _:E_INDIRECTION_RELEASE, _:addressof (Callback_Release_<tResolvedAlloc:>));
mset(closure, _:E_INLINE_CALL_TIMER, YSI_SetTimerEx__(&Inline_MaybeFree_<tAlloc:>, 0, false, YSI_gscSpecifier_i, _:closure));
mset(closure, _:E_INLINE_CALL_TIMER, YSI_SetTimerEx__(&Inline_MaybeFree_<tAlloc:>, 0, false, YSI_gcI, _:closure));
mset(closure, _:E_INLINE_CALL_FLAGS, e_INLINE_FLAG_CONST);
mset(closure, _:E_INDIRECTION_METADATA, 0);
mset(closure, _:E_INDIRECTION_TAG, tag);
Expand Down Expand Up @@ -1673,7 +1670,7 @@ stock Callback_Release(const input[E_CALLBACK_DATA])
static stock Callback_Claim_(func[E_INLINE_CALL])
{
KillTimer(func[E_INLINE_CALL_TIMER]);
func[E_INLINE_CALL_TIMER] = YSI_SetTimerEx__(&Inline_MaybeConst_<tResolvedAlloc:>, 0, false, YSI_gscSpecifier_i, AMX_Ref(func[E_INLINE_CALL:E_INDIRECTION_ALWAYS_NULL]));
func[E_INLINE_CALL_TIMER] = YSI_SetTimerEx__(&Inline_MaybeConst_<tResolvedAlloc:>, 0, false, YSI_gcI, AMX_Ref(func[E_INLINE_CALL:E_INDIRECTION_ALWAYS_NULL]));
}

/*-------------------------------------------------------------------------*//**
Expand Down Expand Up @@ -2165,7 +2162,7 @@ static stock Inline_DoRetnGen(ctx[AsmContext], const scanner[CodeScanner], const
}
}

#define CALL@Inline_OnAsmError%8() Inline_OnAsmError%8("", AsmError:0)
#define CALL@Inline_OnAsmError%8() Inline_OnAsmError%8(YSI_EMPTY, AsmError:0)
#define P@AsmError: P@

static stock Inline_OnAsmError(const ctx[AsmContext], AsmError:error)
Expand Down Expand Up @@ -2254,7 +2251,7 @@ stock Inline_UI_(const &header, tag)
mset(closure, _:E_INDIRECTION_HANDER, _:addressof (Callback_CallHandler_<x>));
mset(closure, _:E_INDIRECTION_CLAIM, _:addressof (Callback_Claim_));
mset(closure, _:E_INDIRECTION_RELEASE, _:addressof (Callback_Release_<tResolvedAlloc:>));
mset(closure, _:E_INLINE_CALL_TIMER, YSI_SetTimerEx__(&Inline_MaybeFree_<tAlloc:>, 0, false, YSI_gscSpecifier_i, _:closure));
mset(closure, _:E_INLINE_CALL_TIMER, YSI_SetTimerEx__(&Inline_MaybeFree_<tAlloc:>, 0, false, YSI_gcI, _:closure));
mset(closure, _:E_INLINE_CALL_FLAGS, e_INLINE_FLAG_CONST);
mset(closure, _:E_INDIRECTION_METADATA, 0);
mset(closure, _:E_INDIRECTION_TAG, tag);
Expand Down
1 change: 1 addition & 0 deletions YSI_Core/y_core/y_core_entry.inc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Optional plugins:
// The most first include, since it determines compiler settings that might be
// used by literally any other include.
#include "..\..\YSI_Server\y_thirdpartyinclude\y_addressof"
#include "y_interning"
#include "y_emit"
#include "y_compilerdata"

Expand Down
194 changes: 194 additions & 0 deletions YSI_Core/y_core/y_interning.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
Legal:
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 the "License"; you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the YSI framework.
The Initial Developer of the Original Code is Alex "Y_Less" Cole.
Portions created by the Initial Developer are Copyright (c) 2022
the Initial Developer. All Rights Reserved.
Contributors:
Y_Less
koolk
JoeBullet/Google63
g_aSlice/Slice
Misiur
samphunter
tianmeta
maddinat0r
spacemud
Crayder
Dayvison
Ahmad45123
Zeex
irinel1996
Yiin-
Chaprnks
Konstantinos
Masterchen09
Southclaws
PatchwerkQWER
m0k1
paulommu
udan111
Cheaterman
Thanks:
JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
ZeeX - Very productive conversations.
koolk - IsPlayerinAreaEx code.
TheAlpha - Danish translation.
breadfish - German translation.
Fireburn - Dutch translation.
yom - French translation.
50p - Polish translation.
Zamaroht - Spanish translation.
Los - Portuguese translation.
Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
me to strive to better.
Pixels^ - Running XScripters where the idea was born.
Matite - Pestering me to release it and using it.
Very special thanks to:
Thiadmer - PAWN, whose limits continue to amaze me!
Kye/Kalcor - SA:MP.
SA:MP Team past, present and future - SA:MP.
Optional plugins:
Gamer_Z - GPS.
Incognito - Streamer.
Me - sscanf2, fixes2, Whirlpool.
*/

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c></c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_EMPTY[] = "";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c> </c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_SPACE[] = " ";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c>i</c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_gcI[] = "i";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c>ii</c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_gcII[] = "ii";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c>iii</c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_gcIII[] = "iii";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c>iiii</c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_gcIIII[] = "iiii";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c>s</c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_gcS[] = "s";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c>isi</c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_gcISI[] = "isi";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c>isii</c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_gcISII[] = "isii";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c>isiii</c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_gcISIII[] = "isiii";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c>isiii</c> defined just once for repeated use.
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_gcISIII[] = "isiii";

/*-------------------------------------------------------------------------*//**
* <library>y_interning</library>
* <remarks>
* The string <c>iiiiiiiiiiiiiiiii</c> defined just once for repeated use.
* Yes, believe it or not this ridiculous string is used in YSI!
* </remarks>
*//*------------------------------------------------------------------------**/

stock const
YSI_gcIIIIIIIIIIIIIIIII[] = "iiiiiiiiiiiiiiiii";

10 changes: 3 additions & 7 deletions YSI_Core/y_core/y_shortfunc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ static stock const
* <library>y_shortfunc</library>
*/
YSI_g_sPropReturn[] = YSIM_RETURN,
/**
* <library>y_shortfunc</library>
*/
YSI_g_sPropEmpty[] = "",
/**
* <library>y_shortfunc</library>
*/
Expand Down Expand Up @@ -249,7 +245,7 @@ stock K@(const function[], const fmat[], GLOBAL_TAG_TYPES:...)
{
// Get the return value. Already have most of the parameters pushed,
// just modify one of them (the name).
#emit CONST.pri YSI_g_sPropEmpty
#emit CONST.pri YSI_EMPTY
#emit STOR.S.pri __local2_offset
#emit LOAD.pri YSI_g_sYSIM_STRING
#emit STOR.S.pri __local1_offset
Expand Down Expand Up @@ -359,7 +355,7 @@ stock D@(const function[], const fmat[], GLOBAL_TAG_TYPES:...)
// Push the current master ID on to the master stack. Returns the old
// master ID stored in the property, which we can shove on to the heap to
// restore later.
#emit PUSH.C YSI_g_sPropEmpty
#emit PUSH.C YSI_EMPTY
#emit PUSH @_
#emit PUSH.C YSI_g_sPropCaller
#emit PUSH.C 8 // Property group, not in cells.
Expand Down Expand Up @@ -516,7 +512,7 @@ stock T@(const string:ret[YSI_MAX_STRING], GLOBAL_TAG_TYPES:...)
{
Debug_Print5("T@ called: %s", ret);
// Return possibly multiple values remotely.
setproperty(8, YSI_g_sPropEmpty, YSIM_STRING, ret);
setproperty(8, YSI_EMPTY, YSIM_STRING, ret);
for (new i = 1, j = numargs(); i != j; ++i)
{
Debug_Print7("T@: loop %d = %d", i, getarg(i));
Expand Down
18 changes: 0 additions & 18 deletions YSI_Core/y_core/y_shortvar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -265,24 +265,6 @@ native V@(GLOBAL_TAG_TYPES:id = 0, const name[] = "", value = cellmin, string[]
NULL[2] = "\1";
#endif

stock const
/**
* <library>y_shortvar</library>
* <remarks>
* A single space in a string, for string interning. Just a micro-
* optimisation to use this instead of <c>" "</c> throughout YSI.
* </remarks>
*/
YSI_SPACE[] = " ",
/**
* <library>y_shortvar</library>
* <remarks>
* An empty string, for string interning. Just a micro-optimisation to use
* this instead of <c>""</c> throughout YSI.
* </remarks>
*/
YSI_EMPTY[] = "";

#if __COMPILER_MODIFIED
#endinput
#endif
Expand Down
6 changes: 3 additions & 3 deletions YSI_Core/y_core/y_version.inc
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ static stock YVers_PrintHeader()
Script_GetStartString(version),
format(version, sizeof (version), "Started: %s", version),
Server_PrintIntroPart(version),
Server_PrintIntroPart(""),
Server_PrintIntroPart(YSI_EMPTY),
Script_GetCompilerString(version, os),
format(version, sizeof (version), "Compiler: %s (%s)", version, os),
Server_PrintIntroPart(version),
Expand All @@ -634,15 +634,15 @@ static stock YVers_PrintHeader()
format(version, sizeof (version), "Built: %s - %s", __date, __time),
Server_PrintIntroPart(version);
#endif
Server_PrintIntroPart(""),
Server_PrintIntroPart(YSI_EMPTY),
Server_PrintIntroPart("YSI: v" YSI_VERSION);
#if defined YSI_NO_MASTER
Server_PrintIntroPart("Master: <none>");
#else
format(version, sizeof (version), "Master: %d", @_),
Server_PrintIntroPart(version);
#endif
Server_PrintIntroPart(""),
Server_PrintIntroPart(YSI_EMPTY),
Server_GetJITString(version),
format(version, sizeof (version), "JIT: %s", version),
Server_PrintIntroPart(version);
Expand Down
6 changes: 1 addition & 5 deletions YSI_Core/y_testing/y_testing_entry.inc
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,7 @@ static stock
stock
YSI_gCurTestName[FUNCTION_LENGTH];

static stock const
YSI_gscStringS[] = "s",
YSI_gscString_[] = "";

#define Y_TESTING_S(%0) ((%0) == 1 ? YSI_gscString_ : YSI_gscStringS)
#define Y_TESTING_S(%0) ((%0) == 1 ? YSI_EMPTY : YSI_gcS)

// Each function type has a dedicated three letter prefix associated with it:
//
Expand Down
Loading

0 comments on commit 35c7c43

Please sign in to comment.