[Scummvm-git-logs] scummvm master -> 2071b870a1d3f017520a4e05afe7161255cf8d78
Strangerke
noreply at scummvm.org
Wed May 15 06:19:38 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
2071b870a1 BAGEL: Move assignments out of if statements and remove useless null checks before deletes in CBagChatWnd, CBagObject, C
Commit: 2071b870a1d3f017520a4e05afe7161255cf8d78
https://github.com/scummvm/scummvm/commit/2071b870a1d3f017520a4e05afe7161255cf8d78
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-15T07:19:30+01:00
Commit Message:
BAGEL: Move assignments out of if statements and remove useless null checks before deletes in CBagChatWnd, CBagObject, CBofPalette, CBofSprite and CQueue
Changed paths:
engines/bagel/baglib/chat_wnd.cpp
engines/bagel/baglib/object.cpp
engines/bagel/boflib/gfx/palette.cpp
engines/bagel/boflib/gfx/sprite.cpp
engines/bagel/boflib/queue.cpp
diff --git a/engines/bagel/baglib/chat_wnd.cpp b/engines/bagel/baglib/chat_wnd.cpp
index a5f2694240d..b9aa21b41cb 100644
--- a/engines/bagel/baglib/chat_wnd.cpp
+++ b/engines/bagel/baglib/chat_wnd.cpp
@@ -51,10 +51,10 @@ void CBagChatWnd::onMouseMove(uint32 flags, CBofPoint *pos, void *) {
CBagStorageDevWnd::onMouseMove(flags, pos);
// If over a chat choice, then highlight it
- CBofList<CBagObject *> *bagObjectList;
+ CBofList<CBagObject *> *bagObjectList = getObjectList();
// Run thru background object list and find if the cursor is over an object
- if ((bagObjectList = getObjectList()) != nullptr) {
+ if (bagObjectList != nullptr) {
// Go thru list backwards to find the 1st top-most object
CBofListNode<CBagObject *> *currNode = bagObjectList->getTail();
while (currNode != nullptr) {
diff --git a/engines/bagel/baglib/object.cpp b/engines/bagel/baglib/object.cpp
index c5bd2b96d29..f1051be68b9 100644
--- a/engines/bagel/baglib/object.cpp
+++ b/engines/bagel/baglib/object.cpp
@@ -94,10 +94,8 @@ CBagObject::CBagObject() {
}
CBagObject::~CBagObject() {
- if (_pMenu != nullptr) {
- delete _pMenu;
- _pMenu = nullptr;
- }
+ delete _pMenu;
+ _pMenu = nullptr;
if (_psName && (_psName != &_sFileName)) {
delete _psName;
@@ -188,13 +186,14 @@ ParseCodes CBagObject::setInfo(CBagIfstream &istr) {
case '{': {
rc = UPDATED_OBJECT;
if (!_pMenu) {
- if ((_pMenu = new CBagMenu) != nullptr) {
-
- // Try to cut down the number of Storage Devices by
- // removing these unused ones from the list.
- //
- g_SDevManager->unregisterStorageDev(_pMenu);
- }
+ _pMenu = new CBagMenu;
+ if (_pMenu == nullptr)
+ fatalError(ERR_MEMORY, "Unable to allocate a new CBagMenu");
+
+ // Try to cut down the number of Storage Devices by
+ // removing these unused ones from the list.
+ //
+ g_SDevManager->unregisterStorageDev(_pMenu);
}
istr.putBack();
diff --git a/engines/bagel/boflib/gfx/palette.cpp b/engines/bagel/boflib/gfx/palette.cpp
index 9cfa314f8ef..35648bd8e30 100644
--- a/engines/bagel/boflib/gfx/palette.cpp
+++ b/engines/bagel/boflib/gfx/palette.cpp
@@ -60,8 +60,8 @@ CBofPalette::~CBofPalette() {
assert(isValidObject(this));
// If we trash the games palette, then reset it back to nullptr.
- CBofApp *pApp;
- if ((pApp = CBofApp::getApp()) != nullptr) {
+ CBofApp *pApp = CBofApp::getApp();
+ if (pApp != nullptr) {
if (this == pApp->getPalette()) {
pApp->setPalette(nullptr);
}
@@ -137,10 +137,8 @@ ErrorCode CBofPalette::createDefault(uint16 nFlags) {
}
ErrorCode CBofPalette::setSharedPalette(const char *pszFileName) {
- if (_pSharedPalette != nullptr) {
- delete _pSharedPalette;
- _pSharedPalette = nullptr;
- }
+ delete _pSharedPalette;
+ _pSharedPalette = nullptr;
// Save name of file used to get the shared palette
if (pszFileName != nullptr) {
@@ -152,11 +150,8 @@ ErrorCode CBofPalette::setSharedPalette(const char *pszFileName) {
CBofPalette *CBofPalette::getSharedPalette() {
// Do we need to load the shared palette?
- if (_pSharedPalette == nullptr) {
- if (fileExists(_szSharedPalFile)) {
- _pSharedPalette = new CBofPalette(_szSharedPalFile);
- }
- }
+ if (_pSharedPalette == nullptr && fileExists(_szSharedPalFile))
+ _pSharedPalette = new CBofPalette(_szSharedPalFile);
return _pSharedPalette;
}
diff --git a/engines/bagel/boflib/gfx/sprite.cpp b/engines/bagel/boflib/gfx/sprite.cpp
index a50fd906ce6..82791ecd854 100644
--- a/engines/bagel/boflib/gfx/sprite.cpp
+++ b/engines/bagel/boflib/gfx/sprite.cpp
@@ -51,7 +51,6 @@ void CBofSprite::openLibrary(CBofPalette *pPal) {
assert(pPal != nullptr);
clearDirtyRect();
-
setSharedPalette(pPal);
// Set up a default work area
@@ -61,7 +60,6 @@ void CBofSprite::openLibrary(CBofPalette *pPal) {
void CBofSprite::closeLibrary() {
flushSpriteChain();
-
tearDownWorkArea();
_pSharedPalette = nullptr;
@@ -71,23 +69,23 @@ void CBofSprite::closeLibrary() {
CBofSprite::CBofSprite() {
_pImage = nullptr; // No initial bitmap image for the sprite
- _cSize = CBofSize(0, 0); // There is no size to the sprite image
+ _cSize = CBofSize(0, 0); // There is no size to the sprite image
_cRect.setRectEmpty(); // Rectangular bounds not yet defined
- _cImageRect = _cRect; // Image rectangle starts same as display bounds
- _cPosition = CBofPoint(0, 0); // Default position to upper left corner of display
+ _cImageRect = _cRect; // Image rectangle starts same as display bounds
+ _cPosition = CBofPoint(0, 0); // Default position to upper left corner of display
_bPositioned = false; // Not yet positioned
_bDuplicated = false; // Not sharing resources with other sprites
_nZOrder = SPRITE_TOPMOST; // Default to top most in fore/back ground order
_nCelCount = 1; // Number of frames in animated cel strip
- _nCelID = _nCelCount - 1; // Cel identifier not pointing at a cel
+ _nCelID = _nCelCount - 1; // Cel identifier not pointing at a cel
_bAnimated = false; // Not initially animated
_bLinked = false; // Not initially linked into the sprite chain
_nMaskColor = NOT_TRANSPARENT; // Default to NO transparency
_bReadOnly = true;
- setBlockAdvance(false); // Default always advance next sprite
+ setBlockAdvance(false); // Default always advance next sprite
}
@@ -95,7 +93,6 @@ CBofSprite::~CBofSprite() {
assert(isValidObject(this));
unlinkSprite();
-
clearImage(); // Clear the sprite image bitmap and context
}
@@ -156,12 +153,13 @@ void CBofSprite::unlinkSprite() {
void CBofSprite::flushSpriteChain() {
- CBofSprite *pSprite = nullptr;
+ CBofSprite *pSprite = getSpriteChain();
// Cycle getting head of chain, un-linking it and then deleting it
- while ((pSprite = CBofSprite::getSpriteChain()) != nullptr) {
+ while (pSprite != nullptr) {
pSprite->unlinkSprite();
delete pSprite;
+ pSprite = getSpriteChain();
}
}
@@ -177,7 +175,8 @@ bool CBofSprite::setupWorkArea(int dx, int dy) {
}
// Create an offscreen bitmap where we do all the work;
- if ((_pWorkBmp = new CBofBitmap(dx, dy, _pSharedPalette)) != nullptr) {
+ _pWorkBmp = new CBofBitmap(dx, dy, _pSharedPalette);
+ if (_pWorkBmp != nullptr) {
_nWorkDX = dx;
_nWorkDY = dy;
bSuccess = true;
@@ -188,10 +187,8 @@ bool CBofSprite::setupWorkArea(int dx, int dy) {
void CBofSprite::tearDownWorkArea() {
- if (_pWorkBmp != nullptr) {
- delete _pWorkBmp;
- _pWorkBmp = nullptr;
- }
+ delete _pWorkBmp;
+ _pWorkBmp = nullptr;
}
diff --git a/engines/bagel/boflib/queue.cpp b/engines/bagel/boflib/queue.cpp
index 38bf3b1c941..17c057a7b3d 100644
--- a/engines/bagel/boflib/queue.cpp
+++ b/engines/bagel/boflib/queue.cpp
@@ -36,12 +36,10 @@ CQueue::CQueue(void *pObject) {
}
CQueue::CQueue(CQueue *pQueue) {
- CLList *pList;
-
// Validate input queue
assert(pQueue != nullptr);
- pList = pQueue->_pQueueList;
+ CLList *pList = pQueue->_pQueueList;
while (pList != nullptr) {
addItem(pList->getData());
pList = pList->getNext();
@@ -49,9 +47,7 @@ CQueue::CQueue(CQueue *pQueue) {
}
CQueue::CQueue(const CQueue &cQueue) {
- CLList *pList;
-
- pList = cQueue._pQueueList;
+ CLList *pList = cQueue._pQueueList;
while (pList != nullptr) {
addItem(pList->getData());
pList = pList->getNext();
@@ -73,9 +69,8 @@ void CQueue::addItem(void *pObject) {
// Make sure this object exists
assert(isValidObject(this));
- CLList *pNewItem;
-
- if ((pNewItem = new CLList(pObject)) != nullptr) {
+ CLList *pNewItem = new CLList(pObject);
+ if (pNewItem != nullptr) {
if (_pQueueList != nullptr) {
_pQueueList->addToTail(pNewItem);
} else {
@@ -90,14 +85,11 @@ void *CQueue::removeItem() {
// Make sure this object exists
assert(isValidObject(this));
- CLList *pList;
- void *pObject;
-
// Assume empty list
- pObject = nullptr;
-
- if ((pList = _pQueueList) != nullptr) {
+ void *pObject = nullptr;
+ CLList *pList = _pQueueList;
+ if (pList != nullptr) {
pObject = pList->getData();
_pQueueList = pList->getNext();
@@ -112,11 +104,9 @@ void CQueue::deleteItem(void *pItem) {
assert(isValidObject(this));
assert(pItem != nullptr);
- CLList *pList, *pNext;
-
- pList = _pQueueList;
+ CLList *pList = _pQueueList;
while (pList != nullptr) {
- pNext = pList->getNext();
+ CLList *pNext = pList->getNext();
if (pItem == pList->getData()) {
// If this is the 1st item in the Queue, then move head
@@ -134,9 +124,7 @@ void CQueue::deleteItem(void *pItem) {
void *CQueue::getQItem() {
assert(isValidObject(this));
- void *pItem;
-
- pItem = nullptr;
+ void *pItem = nullptr;
if (_pQueueList != nullptr) {
pItem = _pQueueList->getData();
}
More information about the Scummvm-git-logs
mailing list