ObjFW  Check-in [3274500ffd]

Overview
Comment:OFMutableArray: Fix an inconsistency
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3274500ffd9b69d339162a0363492c292b96be561076005b6045372961708e18
User & Date: js on 2024-04-14 09:48:44
Other Links: manifest | tags
Context
2024-04-14
10:09
Update ChangeLog for 1.0.12 check-in: 26a4edd972 user: js tags: trunk
09:50
Merge trunk into 1.1 branch check-in: 9991eaba2b user: js tags: 1.1
09:48
OFMutableArray: Fix an inconsistency check-in: 3274500ffd user: js tags: trunk
09:34
GitHub Actions: Add UCRT64 to MinGW on Fedora check-in: 8523df3211 user: js tags: trunk
Changes

Modified src/OFMutableArray.h from [0f29e4e52a] to [f701e95621].

130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144







-
+







 *
 * @param index The index of the object to replace
 * @param object The replacement object
 */
- (void)setObject: (ObjectType)object atIndexedSubscript: (size_t)index;

/**
 * @brief Replaces the first object that has the same address as the specified
 * @brief Replaces all objects that have the same address as the specified
 *	  object with the other specified object.
 *
 * @param oldObject The object to replace
 * @param newObject The replacement object
 */
- (void)replaceObjectIdenticalTo: (ObjectType)oldObject
		      withObject: (ObjectType)newObject;

Modified src/OFMutableArray.m from [201e964807] to [5945457370].

243
244
245
246
247
248
249
250
251


252
253
254
255
256
257
258
259
260
261
262
263
243
244
245
246
247
248
249


250
251
252




253
254
255
256
257
258
259







-
-
+
+

-
-
-
-







	size_t count;

	if (oldObject == nil || newObject == nil)
		@throw [OFInvalidArgumentException exception];

	count = self.count;

	for (size_t i = 0; i < count; i++) {
		if ([self objectAtIndex: i] == oldObject) {
	for (size_t i = 0; i < count; i++)
		if ([self objectAtIndex: i] == oldObject)
			[self replaceObjectAtIndex: i withObject: newObject];

			return;
		}
	}
}

- (void)removeObjectAtIndex: (size_t)idx
{
	OF_UNRECOGNIZED_SELECTOR
}

Modified tests/OFMutableArrayTests.m from [840215fb12] to [96c3237cac].

84
85
86
87
88
89
90


91
92
93
94
95


96
97
98
99
100
101
102
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
105







+
+




-
+
+







	    ([OFArray arrayWithObjects: @"Foo", @"Foo", @"Foo", @"Baz", nil]));
}

- (void)testReplaceObjectIdenticalToWithObject
{
	[_mutableArray insertObject: [[cArray[1] mutableCopy] autorelease]
			    atIndex: 1];
	[_mutableArray insertObject: [[cArray[1] mutableCopy] autorelease]
			    atIndex: 4];
	[_mutableArray replaceObjectIdenticalTo: cArray[1]
				     withObject: cArray[0]];

	OTAssertEqualObjects(_mutableArray,
	    ([OFArray arrayWithObjects: @"Foo", @"Bar", @"Foo", @"Baz", nil]));
	    ([OFArray arrayWithObjects: @"Foo", @"Bar", @"Foo", @"Baz", @"Bar",
	    nil]));
}

- (void)testReplaceObjectAtIndexWithObject
{
	[_mutableArray replaceObjectAtIndex: 1
				 withObject: cArray[0]];