ObjFW  Check-in [855de7c3a7]

Overview
Comment:Implement -[OFString_UTF8 hash] for better performance.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 855de7c3a7097d1ddc72e620227cd5c0e90fe4101ce5dbcf7e3612ba3719ceef
User & Date: js on 2011-11-21 16:47:57
Other Links: manifest | tags
Context
2011-11-23
00:21
Add an implementation of strptime. check-in: bfdf9135d3 user: js tags: trunk
2011-11-21
16:47
Implement -[OFString_UTF8 hash] for better performance. check-in: 855de7c3a7 user: js tags: trunk
16:47
There is no need to hash 32 bit per character if Unicode has only 24. check-in: d8a6ca3fbd user: js tags: trunk
Changes

Modified src/OFString_UTF8.m from [3609f3a164] to [a98ac09f1e].

711
712
713
714
715
716
717
718
719
720


721

722



723
















724
725
726
727
728
729
730
		return OF_ORDERED_DESCENDING;
	else if (s->cStringLength - i < otherCStringLength - j)
		return OF_ORDERED_ASCENDING;

	return OF_ORDERED_SAME;
}

/* TODO
- (uint32_t)hash
{


	IMPLEMENT

}



*/

















- (of_unichar_t)characterAtIndex: (size_t)index
{
	of_unichar_t character;

	if (index >= s->length)
		@throw [OFOutOfRangeException exceptionWithClass: isa];







<


>
>
|
>
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







711
712
713
714
715
716
717

718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
		return OF_ORDERED_DESCENDING;
	else if (s->cStringLength - i < otherCStringLength - j)
		return OF_ORDERED_ASCENDING;

	return OF_ORDERED_SAME;
}


- (uint32_t)hash
{
	size_t i;
	uint32_t hash;

	OF_HASH_INIT(hash);

	for (i = 0; i < s->cStringLength; i++) {
		of_unichar_t c;
		size_t length;

		if ((length = of_string_utf8_to_unicode(s->cString + i,
		    s->cStringLength - i, &c)) == 0)
			@throw [OFInvalidEncodingException
			    exceptionWithClass: isa];

		OF_HASH_ADD(hash, (c & 0xFF0000) >> 16);
		OF_HASH_ADD(hash, (c & 0x00FF00) >>  8);
		OF_HASH_ADD(hash,  c & 0x0000FF);

		i += length - 1;
	}

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (of_unichar_t)characterAtIndex: (size_t)index
{
	of_unichar_t character;

	if (index >= s->length)
		@throw [OFOutOfRangeException exceptionWithClass: isa];