adium 2708:768360f76468: This UTF8String message was using 9–2...

commits at adium.im commits at adium.im
Sat Sep 12 18:40:18 UTC 2009


details:	http://hg.adium.im/adium/rev/768360f76468
revision:	2708:768360f76468
author:		Peter Hosey <hg at boredzo.org>
date:		Sat Sep 12 11:33:03 2009 -0700

This UTF8String message was using 9–21% of the time in GetTextContentForHTMLLog. Now, instead of decoding the UTF-8 into an NSString and then immediately encoding it back out again, we simply read the original UTF-8 data directly into a null-terminated buffer.
Subject: adium 2709:7b3d938c3f53: Added code to the test app to track how many files it's “imported” and how long it's taken. This reports 0.007231 seconds per file on my machine.

details:	http://hg.adium.im/adium/rev/7b3d938c3f53
revision:	2709:7b3d938c3f53
author:		Peter Hosey <hg at boredzo.org>
date:		Sat Sep 12 11:39:55 2009 -0700

Added code to the test app to track how many files it's “imported” and how long it's taken. This reports 0.007231 seconds per file on my machine.

diffs (103 lines):

diff -r 91f8ba5821d4 -r 7b3d938c3f53 Other/Adium Spotlight Importer/AFSIAppDelegate.m
--- a/Other/Adium Spotlight Importer/AFSIAppDelegate.m	Sat Sep 12 11:10:35 2009 -0700
+++ b/Other/Adium Spotlight Importer/AFSIAppDelegate.m	Sat Sep 12 11:39:55 2009 -0700
@@ -15,12 +15,13 @@
 
 @implementation AFSIAppDelegate
 
-- (void) importOneChatlogFromPath:(NSString *)path {
+- (void) importOneChatlogFromPath:(NSString *)path numFilesProcessed:(inout NSUInteger *)numFilesProcessed {
 	NSError *error = nil;
 	GetMetadataForFile(NULL, [NSMutableDictionary dictionary], [[NSWorkspace sharedWorkspace] typeOfFile:path error:&error], path);
+	++*numFilesProcessed;
 }
 
-- (void) importChatlogsFromDirectoryTreeRootedAtPath:(NSString *)rootPath {
+- (void) importChatlogsFromDirectoryTreeRootedAtPath:(NSString *)rootPath numFilesProcessed:(inout NSUInteger *)numFilesProcessedPtr {
 	NSFileManager *mgr = [NSFileManager defaultManager];
 	NSDirectoryEnumerator *dirEnum = [mgr enumeratorAtPath:rootPath];
 	for (NSString *subpath in dirEnum) {
@@ -30,28 +31,35 @@
 			BOOL isDir = NO;
 			if ([mgr fileExistsAtPath:path isDirectory:&isDir] && isDir)
 				[dirEnum skipDescendents];
-			[self importOneChatlogFromPath:path];
+			[self importOneChatlogFromPath:path numFilesProcessed:numFilesProcessedPtr];
 		} else if ([ext caseInsensitiveCompare:@"AdiumLog"] == NSOrderedSame)
-			[self importOneChatlogFromPath:path];
+			[self importOneChatlogFromPath:path numFilesProcessed:numFilesProcessedPtr];
 		else if ([ext caseInsensitiveCompare:@"AdiumHTMLLog"] == NSOrderedSame)
-			[self importOneChatlogFromPath:path];
+			[self importOneChatlogFromPath:path numFilesProcessed:numFilesProcessedPtr];
 	}
 }
 
 - (void) application:(NSApplication *)sender openFiles:(NSArray *)paths {
+	NSUInteger numFilesProcessed = 0;
+	NSDate *start, *end;
+	start = [NSDate date];
+
 	NSFileManager *mgr = [NSFileManager defaultManager];
 	for (NSString *path in paths) {
 		BOOL isDir = NO;
 		if ([mgr fileExistsAtPath:path isDirectory:&isDir]) {
 			if (isDir)
-				[self importChatlogsFromDirectoryTreeRootedAtPath:path];
+				[self importChatlogsFromDirectoryTreeRootedAtPath:path numFilesProcessed:&numFilesProcessed];
 			else
-				[self importOneChatlogFromPath:path];
+				[self importOneChatlogFromPath:path numFilesProcessed:&numFilesProcessed];
 		}
 	}
 
+	end = [NSDate date];
+	NSTimeInterval timeTaken = [end timeIntervalSinceDate:start];
+
 	NSBeep();
-	NSLog(@"Job's done!");
+	NSLog(@"Job's done! Processed %lu files in %f seconds (%f seconds per file)", numFilesProcessed, timeTaken, timeTaken / numFilesProcessed);
 }
 
 @end
diff -r 91f8ba5821d4 -r 7b3d938c3f53 Other/Adium Spotlight Importer/GetMetadataForHTMLLog.m
--- a/Other/Adium Spotlight Importer/GetMetadataForHTMLLog.m	Sat Sep 12 11:10:35 2009 -0700
+++ b/Other/Adium Spotlight Importer/GetMetadataForHTMLLog.m	Sat Sep 12 11:39:55 2009 -0700
@@ -8,6 +8,8 @@
 #import "GetMetadataForHTMLLog.h"
 #import "GetMetadataForHTMLLog-Additions.h"
 
+#include <sys/stat.h>
+
 static char *gaim_markup_strip_html(const char *str);
 
 //Scan an Adium date string, supahfast C style
@@ -104,11 +106,26 @@
 	/* Perhaps we want to decode the HTML instead of stripping it so we can process
 	 * the attributed contents to turn links into link (URL) for searching purposes...
 	 */
-	NSString	*textContent = [NSString stringWithContentsOfUTF8File:pathToFile];
+	NSString *textContent;
 
-	if (textContent) {
+	NSMutableData *UTF8Data = nil;
+	char *UTF8HTMLCString = nil;
+
+	int fd = open([pathToFile fileSystemRepresentation], O_RDONLY);
+	if (fd > -1) {
+		struct stat sb;
+		if (fstat(fd, &sb) == 0) {
+			UTF8Data = [NSMutableData dataWithLength:sb.st_size + 1UL];
+			UTF8HTMLCString = [UTF8Data mutableBytes];
+			if (UTF8HTMLCString != NULL)
+				read(fd, UTF8HTMLCString, sb.st_size);
+		}
+		close(fd);
+	}
+
+	if (UTF8HTMLCString) {
 		//Strip the HTML markup
-		char *plainText = gaim_markup_strip_html([textContent UTF8String]);
+		char *plainText = gaim_markup_strip_html(UTF8HTMLCString);
 		textContent = [NSString stringWithUTF8String:plainText];
 		free((void *)plainText);
 	} else {


More information about the commits mailing list