[Scummvm-git-logs] scummvm master -> a77181cdde7e9ce1f21f0971a81a9f449dc37721
mduggan
mgithub at guarana.org
Thu Mar 4 09:50:04 UTC 2021
This automated email contains information about 7 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
06e3537155 PRIVATE: Reduce Datum copies slightly
9debfbb4ab PRIVATE: Reduce string-based memory leaks, improve constness
bfc73657f5 PRIVATE: Avoid one array copy on function call
551ee85bf3 PRIVATE: Avoid some string copies
18199d8777 PRIVATE: Remove some string memory leaks
14b440605d PRIVATE: Remove a Rect memory leak
a77181cdde PRIVATE: Remove Point memory leak
Commit: 06e3537155da7bd3ed65f7ac4e14e5471956dc3c
https://github.com/scummvm/scummvm/commit/06e3537155da7bd3ed65f7ac4e14e5471956dc3c
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2021-03-04T18:03:36+09:00
Commit Message:
PRIVATE: Reduce Datum copies slightly
Changed paths:
engines/private/code.cpp
engines/private/grammar.h
diff --git a/engines/private/code.cpp b/engines/private/code.cpp
index e2a6213af4..1b3af9cca4 100644
--- a/engines/private/code.cpp
+++ b/engines/private/code.cpp
@@ -77,11 +77,11 @@ void SettingMaps::init() {
g_vm->_stackp = Gen::g_vm->_stack;
}
-void SettingMaps::save(char *name) {
+void SettingMaps::save(const char *name) {
_map.setVal(name, _setting);
}
-void SettingMaps::load(Common::String &name) {
+void SettingMaps::load(const Common::String &name) {
assert(_map.contains(name));
_setting = _map.getVal(name);
@@ -105,7 +105,7 @@ Datum pop() {
}
/* push d onto stack */
-int push(Datum d) {
+int push(const Datum &d) {
assert (!(g_vm->_stackp >= &g_vm->_stack[NSTACK]));
*g_vm->_stackp++ = d;
return 0;
@@ -144,14 +144,13 @@ int varpush() { /* push variable onto stack */
}
int funcpush() {
- Datum s, n, arg;
- s = pop();
- n = pop();
+ Datum s = pop();
+ Datum n = pop();
ArgArray args;
debugC(1, kPrivateDebugCode, "executing %s with %d params", s.u.str, n.u.val);
for (int i = 0; i < n.u.val; i++) {
- arg = pop();
+ Datum arg = pop();
args.insert(args.begin(), arg) ;
}
@@ -161,8 +160,7 @@ int funcpush() {
/* evaluate variable on stack */
int eval() {
- Datum d;
- d = pop();
+ Datum d = pop();
if (d.u.sym->type == NUM) {
d.type = NUM;
d.u.val = d.u.sym->u.val;
@@ -184,9 +182,8 @@ int eval() {
/* add top two elems on stack */
int add() {
- Datum d1, d2;
- d2 = pop();
- d1 = pop();
+ Datum d2 = pop();
+ Datum d1 = pop();
if (d1.type == NAME) {
d1.u.val = d1.u.sym->u.val;
d1.type = NUM;
@@ -207,8 +204,7 @@ int add() {
}
int negate() {
- Datum d;
- d = pop();
+ Datum d = pop();
int v;
if (d.type == NAME) {
//debug("negating %s", d.u.sym->name->c_str());
@@ -225,9 +221,8 @@ int negate() {
}
int gt() {
- Datum d1, d2;
- d2 = pop();
- d1 = pop();
+ Datum d2 = pop();
+ Datum d1 = pop();
if (d1.type == NAME) {
//char *name = d1.u.sym->name->c_str();
//debug("eval %s to %d",
@@ -248,9 +243,8 @@ int gt() {
}
int lt() {
- Datum d1, d2;
- d2 = pop();
- d1 = pop();
+ Datum d2 = pop();
+ Datum d1 = pop();
if (d1.type == NAME) {
//char *name = d1.u.sym->name->c_str();
//debug("eval %s to %d",
@@ -271,9 +265,8 @@ int lt() {
}
int ge() {
- Datum d1, d2;
- d2 = pop();
- d1 = pop();
+ Datum d2 = pop();
+ Datum d1 = pop();
if (d1.type == NAME) {
//char *name = d1.u.sym->name->c_str();
//debug("eval %s to %d",
@@ -294,9 +287,8 @@ int ge() {
}
int le() {
- Datum d1, d2;
- d2 = pop();
- d1 = pop();
+ Datum d2 = pop();
+ Datum d1 = pop();
if (d1.type == NAME) {
//char *name = d1.u.sym->name->c_str();
//debug("eval %s to %d",
@@ -317,9 +309,8 @@ int le() {
}
int eq() {
- Datum d1, d2;
- d2 = pop();
- d1 = pop();
+ Datum d2 = pop();
+ Datum d1 = pop();
if (d1.type == NAME) {
//char *name = d1.u.sym->name->c_str();
//debug("eval %s to %d",
@@ -340,9 +331,8 @@ int eq() {
}
int ne() {
- Datum d1, d2;
- d2 = pop();
- d1 = pop();
+ Datum d2 = pop();
+ Datum d1 = pop();
if (d1.type == NAME) {
d1.u.val = d1.u.sym->u.val;
d1.type = NUM;
@@ -359,7 +349,7 @@ int ne() {
}
/* install one instruction or operand */
-Inst *code(Inst f) {
+Inst *code(const Inst &f) {
//debugC(1, kPrivateDebugCode, "pushing code at %x", progp);
Inst *oprogp = g_vm->_progp;
assert (!(g_vm->_progp >= &g_vm->_prog[NPROG]));
@@ -368,12 +358,11 @@ Inst *code(Inst f) {
}
int ifcode() {
- Datum d;
Inst *savepc = g_vm->_pc; /* then part */
debugC(1, kPrivateDebugCode, "ifcode: evaluating condition");
execute(savepc+3); /* condition */
- d = pop();
+ Datum d = pop();
debugC(1, kPrivateDebugCode, "ifcode: selecting branch");
@@ -395,8 +384,7 @@ int ifcode() {
}
int randbool() {
- Datum d;
- d = pop();
+ Datum d = pop();
int v = g_private->getRandomBool(d.u.val);
diff --git a/engines/private/grammar.h b/engines/private/grammar.h
index d1cd6b5bb0..b7c797d231 100644
--- a/engines/private/grammar.h
+++ b/engines/private/grammar.h
@@ -76,8 +76,8 @@ public:
SettingMap _map;
void init();
- void save(char *);
- void load(Common::String &);
+ void save(const char *);
+ void load(const Common::String &);
};
extern SettingMaps *g_setts;
@@ -107,9 +107,9 @@ public:
extern VM *g_vm;
Datum pop();
-int push(Datum);
+int push(const Datum &);
-Inst *code(Inst);
+Inst *code(const Inst &);
int eval();
int add();
int negate();
Commit: 9debfbb4abe6f75cd0f055842bb7545b5820f769
https://github.com/scummvm/scummvm/commit/9debfbb4abe6f75cd0f055842bb7545b5820f769
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2021-03-04T18:13:08+09:00
Commit Message:
PRIVATE: Reduce string-based memory leaks, improve constness
Changed paths:
engines/private/symbol.cpp
engines/private/symbol.h
diff --git a/engines/private/symbol.cpp b/engines/private/symbol.cpp
index e81fcb4e1a..3451b6e086 100644
--- a/engines/private/symbol.cpp
+++ b/engines/private/symbol.cpp
@@ -50,9 +50,9 @@
namespace Private {
-void SymbolMaps::defineSymbol(char *n, Common::Rect *r) {
- Common::String *s = new Common::String(n);
- stringToDefine.push(*s);
+void SymbolMaps::defineSymbol(const char *n, Common::Rect *r) {
+ Common::String s(n);
+ stringToDefine.push(s);
rectToDefine.push(r);
}
@@ -72,14 +72,14 @@ void setSymbol(Symbol *s, int v) {
}
/* find s in symbol table symlist */
-Symbol *lookup(Common::String s, SymbolMap symlist) {
+Symbol *lookup(const Common::String &s, SymbolMap symlist) {
Symbol *r = symlist.getVal(s);
return r;
}
/* install some symbol s in a symbol table */
-static Symbol *install(Common::String *n, int t, int d, const char *s, Common::Rect *r, SymbolMap *symlist) {
- Common::String *name = new Common::String(*n);
+static Symbol *install(const Common::String &n, int t, int d, const char *s, Common::Rect *r, SymbolMap *symlist) {
+ Common::String *name = new Common::String(n);
Symbol *sp;
@@ -95,62 +95,59 @@ static Symbol *install(Common::String *n, int t, int d, const char *s, Common::R
else
assert(0);
- symlist->setVal(*n, sp);
+ symlist->setVal(n, sp);
assert(symlist->size() > 0);
return sp;
}
/* lookup some name in some symbol table */
-Symbol *SymbolMaps::lookupName(char *n) {
+Symbol *SymbolMaps::lookupName(const char *n) {
//debug("looking up %s", n);
- Common::String *s = new Common::String(n);
+ Common::String s(n);
- if (settings.contains(*s))
- return lookup(*s, settings);
+ if (settings.contains(s))
+ return lookup(s, settings);
- else if (variables.contains(*s))
- return lookup(*s, variables);
+ else if (variables.contains(s))
+ return lookup(s, variables);
- else if (cursors.contains(*s))
- return lookup(*s, cursors);
+ else if (cursors.contains(s))
+ return lookup(s, cursors);
- else if (locations.contains(*s))
- return lookup(*s, locations);
+ else if (locations.contains(s))
+ return lookup(s, locations);
- else if (rects.contains(*s))
- return lookup(*s, rects);
+ else if (rects.contains(s))
+ return lookup(s, rects);
else {
- debugC(1, kPrivateDebugCode, "WARNING: %s not defined", s->c_str());
- return constant(STRING, 0, s->c_str());
+ debugC(1, kPrivateDebugCode, "WARNING: %s not defined", s.c_str());
+ return constant(STRING, 0, s.c_str());
}
}
-void SymbolMaps::installAll(char *n) {
- Common::String *s;
- Common::Rect *r;
-
+void SymbolMaps::installAll(const char *n) {
assert(stringToDefine.size() > 0);
while (!stringToDefine.empty()) {
- s = new Common::String(stringToDefine.pop());
- r = rectToDefine.pop();
+ Common::String s = stringToDefine.pop();
+ Common::Rect *r = rectToDefine.pop();
- //debug("name %s", s->c_str());
+ //debug("name %s", s.c_str());
if (strcmp(n, "settings") == 0) {
assert(r == NULL);
- install(s, STRING, 0, s->c_str(), r, &settings);
+ install(s, STRING, 0, s.c_str(), r, &settings);
} else if (strcmp(n, "variables") == 0) {
assert(r == NULL);
install(s, NAME, 0, NULL, r, &variables);
- variableList.push_front(*s);
+ variableList.push_front(s);
} else if (strcmp(n, "cursors") == 0) {
assert(r == NULL);
install(s, NAME, 0, NULL, r, &cursors);
} else if (strcmp(n, "locations") == 0) {
assert(r == NULL);
install(s, NAME, 0, NULL, r, &locations);
- locationList.push_front(*s);
+ locationList.push_front(s);
} else if (strcmp(n, "rects") == 0) {
assert(r != NULL);
install(s, RECT, 0, NULL, r, &rects);
diff --git a/engines/private/symbol.h b/engines/private/symbol.h
index 4f613f4699..47467ab9a5 100644
--- a/engines/private/symbol.h
+++ b/engines/private/symbol.h
@@ -71,9 +71,9 @@ public:
NameList locationList;
Symbol *constant(int t, int d, const char *s);
- Symbol *lookupName(char *n);
- void installAll(char *n);
- void defineSymbol(char *, Common::Rect *);
+ Symbol *lookupName(const char *n);
+ void installAll(const char *n);
+ void defineSymbol(const char *, Common::Rect *);
};
} // End of namespace Private
Commit: bfc73657f589d7ad81cdae7898ffcfa61d0ad84f
https://github.com/scummvm/scummvm/commit/bfc73657f589d7ad81cdae7898ffcfa61d0ad84f
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2021-03-04T18:20:29+09:00
Commit Message:
PRIVATE: Avoid one array copy on function call
Changed paths:
engines/private/funcs.cpp
engines/private/grammar.h
diff --git a/engines/private/funcs.cpp b/engines/private/funcs.cpp
index ef620734c0..3aa8fb2226 100644
--- a/engines/private/funcs.cpp
+++ b/engines/private/funcs.cpp
@@ -755,7 +755,7 @@ FuncTable funcTable[] = {
{ 0, 0}
};
-void call(const char *name, ArgArray args) {
+void call(const char *name, const ArgArray &args) {
Common::String n(name);
if (!g_private->_functions.contains(n)) {
error("I don't know how to execute %s", name);
diff --git a/engines/private/grammar.h b/engines/private/grammar.h
index b7c797d231..2bed773995 100644
--- a/engines/private/grammar.h
+++ b/engines/private/grammar.h
@@ -87,7 +87,7 @@ extern SettingMaps *g_setts;
// Funtions
typedef Common::Array<Datum> ArgArray;
-void call(const char *, ArgArray);
+void call(const char *, const ArgArray &);
// Code Generation and Execution
Commit: 551ee85bf391044dd2e10294969894bb4e0a136e
https://github.com/scummvm/scummvm/commit/551ee85bf391044dd2e10294969894bb4e0a136e
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2021-03-04T18:24:26+09:00
Commit Message:
PRIVATE: Avoid some string copies
Changed paths:
engines/private/cursors.cpp
engines/private/private.cpp
engines/private/private.h
diff --git a/engines/private/cursors.cpp b/engines/private/cursors.cpp
index 6cd318cefc..e8e42bf798 100644
--- a/engines/private/cursors.cpp
+++ b/engines/private/cursors.cpp
@@ -346,7 +346,7 @@ void PrivateEngine::initCursors() {
CursorMan.replaceCursorPalette(cursorPalette, 0, 3);
}
-void PrivateEngine::changeCursor(Common::String cursor) {
+void PrivateEngine::changeCursor(const Common::String &cursor) {
assert(_cursorData.contains(cursor));
Common::Point p = *_cursorPoints.getVal(cursor);
int x, y;
diff --git a/engines/private/private.cpp b/engines/private/private.cpp
index 3d04f60815..23654aff85 100644
--- a/engines/private/private.cpp
+++ b/engines/private/private.cpp
@@ -832,7 +832,7 @@ Common::Error PrivateEngine::saveGameStream(Common::WriteStream *stream, bool is
return Common::kNoError;
}
-Common::String PrivateEngine::convertPath(Common::String name) {
+Common::String PrivateEngine::convertPath(const Common::String &name) {
Common::String path(name);
Common::String s1("\\");
Common::String s2("/");
diff --git a/engines/private/private.h b/engines/private/private.h
index 9c5059957b..5eb1ac8c60 100644
--- a/engines/private/private.h
+++ b/engines/private/private.h
@@ -190,14 +190,14 @@ public:
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
void syncGameStream(Common::Serializer &s);
- Common::String convertPath(Common::String);
+ Common::String convertPath(const Common::String &);
void playVideo(const Common::String &);
void skipVideo();
void loadImage(const Common::String &file, int x, int y);
void drawScreenFrame();
- void changeCursor(Common::String);
+ void changeCursor(const Common::String &);
void initCursors();
// Rendering
Commit: 18199d8777652dc17a25c2ee4b15dcc1d36377c4
https://github.com/scummvm/scummvm/commit/18199d8777652dc17a25c2ee4b15dcc1d36377c4
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2021-03-04T18:27:49+09:00
Commit Message:
PRIVATE: Remove some string memory leaks
Changed paths:
engines/private/cursors.cpp
engines/private/private.cpp
diff --git a/engines/private/cursors.cpp b/engines/private/cursors.cpp
index e8e42bf798..9c556a516d 100644
--- a/engines/private/cursors.cpp
+++ b/engines/private/cursors.cpp
@@ -334,14 +334,14 @@ CursorPointMap _cursorPoints;
void PrivateEngine::initCursors() {
for (Private::CursorDataTable *cur = Private::cursorDataTable; cur->name; cur++) {
- Common::String *name = new Common::String(cur->name);
- _cursorData.setVal(*name, cur->cursor);
+ Common::String name(cur->name);
+ _cursorData.setVal(name, cur->cursor);
}
for (Private::CursorPointTable *cur = Private::cursorPointTable; cur->name; cur++) {
- Common::String *name = new Common::String(cur->name);
+ Common::String name(cur->name);
Common::Point *point = new Common::Point(cur->coord[0], cur->coord[1]);
- _cursorPoints.setVal(*name, point);
+ _cursorPoints.setVal(name, point);
}
CursorMan.replaceCursorPalette(cursorPalette, 0, 3);
}
diff --git a/engines/private/private.cpp b/engines/private/private.cpp
index 23654aff85..c2f0f8a230 100644
--- a/engines/private/private.cpp
+++ b/engines/private/private.cpp
@@ -288,8 +288,8 @@ Common::Error PrivateEngine::run() {
void PrivateEngine::initFuncs() {
for (Private::FuncTable *fnc = funcTable; fnc->name; fnc++) {
- Common::String *name = new Common::String(fnc->name);
- _functions.setVal(*name, (void *)fnc->func);
+ Common::String name(fnc->name);
+ _functions.setVal(name, (void *)fnc->func);
}
}
Commit: 14b440605d88c55c1080f77e1ad9c836c61f2104
https://github.com/scummvm/scummvm/commit/14b440605d88c55c1080f77e1ad9c836c61f2104
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2021-03-04T18:33:55+09:00
Commit Message:
PRIVATE: Remove a Rect memory leak
Changed paths:
engines/private/funcs.cpp
engines/private/private.cpp
engines/private/private.h
diff --git a/engines/private/funcs.cpp b/engines/private/funcs.cpp
index 3aa8fb2226..9a12c1795f 100644
--- a/engines/private/funcs.cpp
+++ b/engines/private/funcs.cpp
@@ -79,7 +79,7 @@ void fDiaryLocList(ArgArray args) {
x1 = args[2].u.val;
y1 = args[3].u.val;
- Common::Rect *rect = new Common::Rect(x1, y1, x2, y2);
+ Common::Rect rect(x1, y1, x2, y2);
g_private->loadLocations(rect);
}
@@ -89,14 +89,12 @@ void fDiaryGoLoc(ArgArray args) {
}
void fDiaryInvList(ArgArray args) {
- Common::Rect *r1, *r2;
-
debugC(1, kPrivateDebugScript, "DiaryInvList(%d, ..)", args[0].u.val);
- r1 = args[1].u.rect;
- r2 = args[2].u.rect;
+ const Common::Rect *r1 = args[1].u.rect;
+ const Common::Rect *r2 = args[2].u.rect;
- g_private->loadInventory(args[0].u.val, r1, r2);
+ g_private->loadInventory(args[0].u.val, *r1, *r2);
}
void fgoto(ArgArray args) {
diff --git a/engines/private/private.cpp b/engines/private/private.cpp
index c2f0f8a230..55cd0fd914 100644
--- a/engines/private/private.cpp
+++ b/engines/private/private.cpp
@@ -1044,7 +1044,7 @@ void PrivateEngine::removeTimer() {
// Diary
-void PrivateEngine::loadLocations(Common::Rect *rect) {
+void PrivateEngine::loadLocations(const Common::Rect &rect) {
uint32 i = 0;
int16 offset = 44;
for (NameList::iterator it = maps.locationList.begin(); it != maps.locationList.end(); ++it) {
@@ -1055,17 +1055,17 @@ void PrivateEngine::loadLocations(Common::Rect *rect) {
Common::String s =
Common::String::format("%sdryloc%d.bmp", _diaryLocPrefix.c_str(), i);
- loadMask(s, rect->left + 120, rect->top + offset, true);
+ loadMask(s, rect.left + 120, rect.top + offset, true);
}
}
}
-void PrivateEngine::loadInventory(uint32 x, Common::Rect *r1, Common::Rect *r2) {
+void PrivateEngine::loadInventory(uint32 x, const Common::Rect &r1, const Common::Rect &r2) {
int16 offset = 0;
for (NameList::iterator it = inventory.begin(); it != inventory.end(); ++it) {
offset = offset + 22;
//debug("%hd %hd", rect->left, rect->top + offset);
- loadMask(*it, r1->left, r1->top + offset, true);
+ loadMask(*it, r1.left, r1.top + offset, true);
}
}
diff --git a/engines/private/private.h b/engines/private/private.h
index 5eb1ac8c60..a7a402edca 100644
--- a/engines/private/private.h
+++ b/engines/private/private.h
@@ -244,8 +244,8 @@ public:
// Diary
InvList inventory;
Common::String _diaryLocPrefix;
- void loadLocations(Common::Rect *);
- void loadInventory(uint32, Common::Rect *, Common::Rect *);
+ void loadLocations(const Common::Rect &);
+ void loadInventory(uint32, const Common::Rect &, const Common::Rect &);
// Save/Load games
MaskInfo _saveGameMask;
Commit: a77181cdde7e9ce1f21f0971a81a9f449dc37721
https://github.com/scummvm/scummvm/commit/a77181cdde7e9ce1f21f0971a81a9f449dc37721
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2021-03-04T18:48:58+09:00
Commit Message:
PRIVATE: Remove Point memory leak
Changed paths:
engines/private/cursors.cpp
engines/private/cursors.h
diff --git a/engines/private/cursors.cpp b/engines/private/cursors.cpp
index 9c556a516d..405dd79e3b 100644
--- a/engines/private/cursors.cpp
+++ b/engines/private/cursors.cpp
@@ -340,7 +340,7 @@ void PrivateEngine::initCursors() {
for (Private::CursorPointTable *cur = Private::cursorPointTable; cur->name; cur++) {
Common::String name(cur->name);
- Common::Point *point = new Common::Point(cur->coord[0], cur->coord[1]);
+ Common::Point point = Common::Point(cur->coord[0], cur->coord[1]);
_cursorPoints.setVal(name, point);
}
CursorMan.replaceCursorPalette(cursorPalette, 0, 3);
@@ -348,7 +348,7 @@ void PrivateEngine::initCursors() {
void PrivateEngine::changeCursor(const Common::String &cursor) {
assert(_cursorData.contains(cursor));
- Common::Point p = *_cursorPoints.getVal(cursor);
+ Common::Point p = _cursorPoints.getVal(cursor);
int x, y;
if (cursor == "default") {
diff --git a/engines/private/cursors.h b/engines/private/cursors.h
index a266d2e176..682863fde6 100644
--- a/engines/private/cursors.h
+++ b/engines/private/cursors.h
@@ -29,7 +29,7 @@
namespace Private {
typedef Common::HashMap<Common::String, const byte *> CursorDataMap;
-typedef Common::HashMap<Common::String, Common::Point *> CursorPointMap;
+typedef Common::HashMap<Common::String, Common::Point> CursorPointMap;
} // End of namespace Private
More information about the Scummvm-git-logs
mailing list