[Scummvm-git-logs] scummvm master -> f1bc2b187c72d7fa165e48b0120a41f7caf4272f

sev- noreply at scummvm.org
Tue Dec 6 22:43:31 UTC 2022


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:
f1bc2b187c COMMON: Optimize some array ops by hoisting storage pointer to a local so the compiler doesn't have to reload it every i


Commit: f1bc2b187c72d7fa165e48b0120a41f7caf4272f
    https://github.com/scummvm/scummvm/commit/f1bc2b187c72d7fa165e48b0120a41f7caf4272f
Author: elasota (ejlasota at gmail.com)
Date: 2022-12-06T23:43:27+01:00

Commit Message:
COMMON: Optimize some array ops by hoisting storage pointer to a local so the compiler doesn't have to reload it every iteration.

Changed paths:
    common/array.h


diff --git a/common/array.h b/common/array.h
index ceba46bc434..bcdda8a9067 100644
--- a/common/array.h
+++ b/common/array.h
@@ -72,8 +72,11 @@ public:
 	 */
 	explicit Array(size_type count) : _size(count) {
 		allocCapacity(count);
+
+		T *storage = _storage;
+
 		for (size_type i = 0; i < count; ++i)
-			new ((void *)&_storage[i]) T();
+			new ((void *)&storage[i]) T();
 	}
 
 	/**
@@ -367,10 +370,14 @@ public:
 	/** Change the size of the array. */
 	void resize(size_type newSize) {
 		reserve(newSize);
+
+		T *storage = _storage;
+
 		for (size_type i = newSize; i < _size; ++i)
-			_storage[i].~T();
+			storage[i].~T();
 		for (size_type i = _size; i < newSize; ++i)
-			new ((void *)&_storage[i]) T();
+			new ((void *)&storage[i]) T();
+
 		_size = newSize;
 	}
 




More information about the Scummvm-git-logs mailing list