ObjFW  Diff

Differences From Artifact [458807374d]:

  • File src/OFMapTable.m — part of check-in [6712442fad] at 2012-12-07 13:57:13 on branch trunk — Revert several OFHashMap related commits.

    This reverts:
    * "Add a per-hashtable seed."
    (cd49c7fcb4b8dca62dccdbf6545d37d86b639eef)
    * "OFMapTable: Reseed on resize."
    (5b545165691cd9ad838c9125b02ff7c857bd4b99)
    * "Add of_random()."
    (9810f191b4e8c1612e7e55095c87e589660fbdba)
    * "OFMapTable: Rotate hash by a random number of bits"
    (3bef412217232d01f202794f7175c130afa1df8f)

    It turned out that these were slowing down all classes based on
    OFHashMap significantly. As there is still no proof that the seeded
    one-at-a-time hash is vulnerable to DoS, these changes were overly
    paranoid. While overly paranoid is usually ok, it is not if it severely
    impacts performance. (user: js, size: 15686) [annotate] [blame] [check-ins using]

To Artifact [1a1f8d234d]:


12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35







+









-







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <stdlib.h>
#include <string.h>

#include <assert.h>

#import "OFMapTable.h"
#import "OFEnumerator.h"

#import "OFEnumerationMutationException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfRangeException.h"

#import "macros.h"

#define MIN_CAPACITY 16

struct of_map_table_bucket {
86
87
88
89
90
91
92

93
94
95





96

97
98
99
100
101
102
103
86
87
88
89
90
91
92
93



94
95
96
97
98

99
100
101
102
103
104
105
106







+
-
-
-
+
+
+
+
+
-
+







	    initWithKeyFunctions: keyFunctions
		  valueFunctions: valueFunctions
			capacity: capacity] autorelease];
}

- init
{
	@try {
	Class c = [self class];
	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c
		[self doesNotRecognizeSelector: _cmd];
		abort();
	} @catch (id e) {
		[self release];
		@throw e;
						    selector: _cmd];
	}
}

- initWithKeyFunctions: (of_map_table_functions_t)keyFunctions_
	valueFunctions: (of_map_table_functions_t)valueFunctions_
{
	return [self initWithKeyFunctions: keyFunctions_
			   valueFunctions: valueFunctions_
620
621
622
623
624
625
626

627
628
629





630

631
632
633
634
635
636
637
623
624
625
626
627
628
629
630



631
632
633
634
635

636
637
638
639
640
641
642
643







+
-
-
-
+
+
+
+
+
-
+







	return valueFunctions;
}
@end

@implementation OFMapTableEnumerator
- init
{
	@try {
	Class c = [self class];
	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c
		[self doesNotRecognizeSelector: _cmd];
		abort();
	} @catch (id e) {
		[self release];
		@throw e;
						    selector: _cmd];
	}
}

- OF_initWithMapTable: (OFMapTable*)mapTable_
	      buckets: (struct of_map_table_bucket**)buckets_
	     capacity: (uint32_t)capacity_
     mutationsPointer: (unsigned long*)mutationsPtr_
{
651
652
653
654
655
656
657
658
659


660
661
662
663
664
665
666
657
658
659
660
661
662
663


664
665
666
667
668
669
670
671
672







-
-
+
+







	[mapTable release];

	[super dealloc];
}

- (void*)nextValue
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
	[self doesNotRecognizeSelector: _cmd];
	abort();
}

- (void)reset
{
	if (*mutationsPtr != mutations)
		@throw [OFEnumerationMutationException
		    exceptionWithClass: [mapTable class]