[Scummvm-git-logs] scummvm master -> 201d2675ad82ae1ae56f24554b67459a736ab21d

whoozle vladimir.menshakov at gmail.com
Mon Aug 31 20:58:09 UTC 2020


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
035ddef16c COMMON: Add ARRAYCLEAR to clear given array using default or provided value.
201d2675ad AUDIO: Replace memsets on structures with ctors with ARRAYCLEAR()


Commit: 035ddef16c26106c49d4f56b53a0bb46c12db7bd
    https://github.com/scummvm/scummvm/commit/035ddef16c26106c49d4f56b53a0bb46c12db7bd
Author: Vladimir Menshakov (vladimir.menshakov at gmail.com)
Date: 2020-08-31T21:57:07+01:00

Commit Message:
COMMON: Add ARRAYCLEAR to clear given array using default or provided value.

Changed paths:
    common/util.h


diff --git a/common/util.h b/common/util.h
index f7c5cbd0ce..58d2b981d6 100644
--- a/common/util.h
+++ b/common/util.h
@@ -81,6 +81,15 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
  */
 #define ARRAYEND(x) ((x) + ARRAYSIZE((x)))
 
+/*
+ * Clear array using default or provided value
+ */
+template<typename T, size_t N> inline void ARRAYCLEAR(T (&array) [N], const T &value = T()) {
+	T * ptr = array;
+	size_t n = N;
+	while(n--)
+		*ptr++ = value;
+}
 
 /**
  * @def SCUMMVM_CURRENT_FUNCTION


Commit: 201d2675ad82ae1ae56f24554b67459a736ab21d
    https://github.com/scummvm/scummvm/commit/201d2675ad82ae1ae56f24554b67459a736ab21d
Author: Vladimir Menshakov (vladimir.menshakov at gmail.com)
Date: 2020-08-31T21:57:14+01:00

Commit Message:
AUDIO: Replace memsets on structures with ctors with ARRAYCLEAR()

Changed paths:
    audio/miles_adlib.cpp
    audio/mods/protracker.cpp
    audio/softsynth/opl/dosbox.cpp


diff --git a/audio/miles_adlib.cpp b/audio/miles_adlib.cpp
index 1450b10222..0bf0bdc9d1 100644
--- a/audio/miles_adlib.cpp
+++ b/audio/miles_adlib.cpp
@@ -25,6 +25,7 @@
 #include "common/file.h"
 #include "common/system.h"
 #include "common/textconsole.h"
+#include "common/util.h"
 
 #include "audio/fmopl.h"
 
@@ -343,9 +344,9 @@ void MidiDriver_Miles_AdLib::onTimer() {
 }
 
 void MidiDriver_Miles_AdLib::resetData() {
-	memset(_midiChannels, 0, sizeof(_midiChannels));
-	memset(_virtualFmVoices, 0, sizeof(_virtualFmVoices));
-	memset(_physicalFmVoices, 0, sizeof(_physicalFmVoices));
+	ARRAYCLEAR(_midiChannels);
+	ARRAYCLEAR(_virtualFmVoices);
+	ARRAYCLEAR(_physicalFmVoices);
 
 	for (byte midiChannel = 0; midiChannel < MILES_MIDI_CHANNEL_COUNT; midiChannel++) {
 		// defaults, were sent to driver during driver initialization
@@ -575,7 +576,7 @@ void MidiDriver_Miles_AdLib::prioritySort() {
 	uint16 virtualFmVoicesCount = 0;
 	byte   midiChannel = 0;
 
-	memset(&virtualPriorities, 0, sizeof(virtualPriorities));
+	ARRAYCLEAR(virtualPriorities);
 
 	//warning("prioritysort");
 
diff --git a/audio/mods/protracker.cpp b/audio/mods/protracker.cpp
index 74df6d9697..a56b421a0d 100644
--- a/audio/mods/protracker.cpp
+++ b/audio/mods/protracker.cpp
@@ -25,6 +25,7 @@
 #include "audio/mods/module.h"
 
 #include "common/textconsole.h"
+#include "common/util.h"
 
 namespace Modules {
 
@@ -169,7 +170,7 @@ ProtrackerStream::ProtrackerStream(Common::SeekableReadStream *stream, int offs,
 
 	_patternDelay = 0;
 
-	memset(_track, 0, sizeof(_track));
+	ARRAYCLEAR(_track);
 
 	startPaula();
 }
diff --git a/audio/softsynth/opl/dosbox.cpp b/audio/softsynth/opl/dosbox.cpp
index 91e81d6bf2..441a61f380 100644
--- a/audio/softsynth/opl/dosbox.cpp
+++ b/audio/softsynth/opl/dosbox.cpp
@@ -166,7 +166,7 @@ bool OPL::init() {
 	free();
 
 	memset(&_reg, 0, sizeof(_reg));
-	memset(_chip, 0, sizeof(_chip));
+	ARRAYCLEAR(_chip);
 
 	_emulator = new DBOPL::Chip();
 	if (!_emulator)




More information about the Scummvm-git-logs mailing list