ObjFW  Check-in [1c65e229e8]

Overview
Comment:Optimize +[stringWithPath:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1c65e229e85d8a7421640736cbf1942a6804eda8bfd36921e7c0e62979d78da9
User & Date: js on 2011-07-09 12:04:52
Other Links: manifest | tags
Context
2011-07-09
13:15
Use OFDataArray instead of OFMutableString in OFXMLElement. check-in: a2c6391204 user: js tags: trunk
12:04
Optimize +[stringWithPath:]. check-in: 1c65e229e8 user: js tags: trunk
03:10
Emphasize that -[readNBytes:intoBuffer:] reads at most n bytes. check-in: e1285e3ba9 user: js tags: trunk
Changes

Modified src/OFString.m from [ee8d4c3fc0] to [d68d151905].

920
921
922
923
924
925
926


927
928


929
930

931
932

933
934
935
936

937
938

939
940

941
942
943
944

945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961





962


963
964

965

966
967
968
969
970
971
972
920
921
922
923
924
925
926
927
928


929
930


931


932




933


934
935
936
937
938
939
940

941


942





943
944
945
946
947
948
949
950
951
952
953
954
955
956

957
958
959

960
961
962
963
964
965
966
967
968
969







+
+
-
-
+
+
-
-
+
-
-
+
-
-
-
-
+
-
-
+


+



-
+
-
-

-
-
-
-
-









+
+
+
+
+
-
+
+

-
+

+







		OFString *component;
		size_t i, cStringLength;
		va_list argumentsCopy;

		s = [self allocMemoryWithSize: sizeof(*s)];
		memset(s, 0, sizeof(*s));

		/*
		 * First needs to be a call to be sure it is initialized, in
		s->cStringLength = [firstComponent cStringLength];

		 * case it's a constant string.
		 */
		switch (of_string_check_utf8([firstComponent cString],
		    s->cStringLength)) {
		s->cStringLength = [firstComponent cStringLength];
		case 1:
			s->isUTF8 = YES;
		s->isUTF8 = firstComponent->s->isUTF8;
			break;
		case -1:
			@throw [OFInvalidEncodingException newWithClass: isa];
		}


		/* Calculate length */
		/* Calculate length and see if we need UTF-8 */
		va_copy(argumentsCopy, arguments);
		while ((component = va_arg(argumentsCopy, OFString*)) != nil) {
			/* First needs to be a call, see above */
			cStringLength = [component cStringLength];
			s->cStringLength += 1 + cStringLength;

			switch (of_string_check_utf8([component cString],
			if (component->s->isUTF8)
			    cStringLength)) {
			case 1:
				s->isUTF8 = YES;
				break;
			case -1:
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}
		}

		s->cString = [self allocMemoryWithSize: s->cStringLength + 1];

		cStringLength = [firstComponent cStringLength];
		memcpy(s->cString, [firstComponent cString], cStringLength);
		i = cStringLength;

		while ((component = va_arg(arguments, OFString*)) != nil) {
			/*
			 * We already sent each component a message, so we can
			 * be sure they are initialized and access them
			 * directly.
			 */
			cStringLength = [component cStringLength];
			cStringLength = component->s->cStringLength;

			s->cString[i] = OF_PATH_DELIMITER;
			memcpy(s->cString + i + 1, [component cString],
			memcpy(s->cString + i + 1, component->s->cString,
			    cStringLength);

			i += 1 + cStringLength;
		}

		s->cString[i] = '\0';
	} @catch (id e) {
		[self release];
		@throw e;