Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STJr
SRB2
Commits
2e3c1105
Commit
2e3c1105
authored
5 years ago
by
LJ Sonic
Browse files
Options
Downloads
Patches
Plain Diff
Optimise string archiving and allow for longer strings
parent
5c16e334
No related branches found
No related tags found
2 merge requests
!985
Shaders next merge
,
!904
Optimise net-archiving of Lua strings, numbers and booleans
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lua_script.c
+23
-8
23 additions, 8 deletions
src/lua_script.c
with
23 additions
and
8 deletions
src/lua_script.c
+
23
−
8
View file @
2e3c1105
...
@@ -732,7 +732,8 @@ enum
...
@@ -732,7 +732,8 @@ enum
ARCH_NULL
=
0
,
ARCH_NULL
=
0
,
ARCH_BOOLEAN
,
ARCH_BOOLEAN
,
ARCH_SIGNED
,
ARCH_SIGNED
,
ARCH_STRING
,
ARCH_SMALLSTRING
,
ARCH_LARGESTRING
,
ARCH_TABLE
,
ARCH_TABLE
,
ARCH_MOBJINFO
,
ARCH_MOBJINFO
,
...
@@ -829,10 +830,9 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
...
@@ -829,10 +830,9 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
}
}
case
LUA_TSTRING
:
case
LUA_TSTRING
:
{
{
UINT
16
len
=
(
UINT
16
)
lua_objlen
(
gL
,
myindex
);
// get length of string, including embedded zeros
UINT
32
len
=
(
UINT
32
)
lua_objlen
(
gL
,
myindex
);
// get length of string, including embedded zeros
const
char
*
s
=
lua_tostring
(
gL
,
myindex
);
const
char
*
s
=
lua_tostring
(
gL
,
myindex
);
UINT16
i
=
0
;
UINT32
i
=
0
;
WRITEUINT8
(
save_p
,
ARCH_STRING
);
// if you're wondering why we're writing a string to save_p this way,
// if you're wondering why we're writing a string to save_p this way,
// it turns out that Lua can have embedded zeros ('\0') in the strings,
// it turns out that Lua can have embedded zeros ('\0') in the strings,
// so we can't use WRITESTRING as that cuts off when it finds a '\0'.
// so we can't use WRITESTRING as that cuts off when it finds a '\0'.
...
@@ -840,7 +840,16 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
...
@@ -840,7 +840,16 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
// fixing the awful crashes previously encountered for reading strings longer than 1024
// fixing the awful crashes previously encountered for reading strings longer than 1024
// (yes I know that's kind of a stupid thing to care about, but it'd be evil to trim or ignore them?)
// (yes I know that's kind of a stupid thing to care about, but it'd be evil to trim or ignore them?)
// -- Monster Iestyn 05/08/18
// -- Monster Iestyn 05/08/18
WRITEUINT16
(
save_p
,
len
);
// save size of string
if
(
len
<
255
)
{
WRITEUINT8
(
save_p
,
ARCH_SMALLSTRING
);
WRITEUINT8
(
save_p
,
len
);
// save size of string
}
else
{
WRITEUINT8
(
save_p
,
ARCH_LARGESTRING
);
WRITEUINT32
(
save_p
,
len
);
// save size of string
}
while
(
i
<
len
)
while
(
i
<
len
)
WRITECHAR
(
save_p
,
s
[
i
++
]);
// write chars individually, including the embedded zeros
WRITECHAR
(
save_p
,
s
[
i
++
]);
// write chars individually, including the embedded zeros
break
;
break
;
...
@@ -1184,15 +1193,21 @@ static UINT8 UnArchiveValue(int TABLESINDEX)
...
@@ -1184,15 +1193,21 @@ static UINT8 UnArchiveValue(int TABLESINDEX)
case
ARCH_SIGNED
:
case
ARCH_SIGNED
:
lua_pushinteger
(
gL
,
READFIXED
(
save_p
));
lua_pushinteger
(
gL
,
READFIXED
(
save_p
));
break
;
break
;
case
ARCH_STRING
:
case
ARCH_SMALLSTRING
:
case
ARCH_LARGESTRING
:
{
{
UINT
16
len
=
READUINT16
(
save_p
);
// length of string, including embedded zeros
UINT
32
len
;
char
*
value
;
char
*
value
;
UINT16
i
=
0
;
UINT32
i
=
0
;
// See my comments in the ArchiveValue function;
// See my comments in the ArchiveValue function;
// it's much the same for reading strings as writing them!
// it's much the same for reading strings as writing them!
// (i.e. we can't use READSTRING either)
// (i.e. we can't use READSTRING either)
// -- Monster Iestyn 05/08/18
// -- Monster Iestyn 05/08/18
if
(
type
==
ARCH_SMALLSTRING
)
len
=
READUINT8
(
save_p
);
// length of string, including embedded zeros
else
len
=
READUINT32
(
save_p
);
// length of string, including embedded zeros
value
=
malloc
(
len
);
// make temp buffer of size len
value
=
malloc
(
len
);
// make temp buffer of size len
// now read the actual string
// now read the actual string
while
(
i
<
len
)
while
(
i
<
len
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment