adium 3120:bb6ae18089d0: Remove global scoping in CBPurpleOscarA...
commits at adium.im
commits at adium.im
Fri Feb 12 04:42:32 UTC 2010
details: http://hg.adium.im/adium/rev/bb6ae18089d0
revision: 3120:bb6ae18089d0
author: Stephen Holt <sholt at adium.im>
date: Thu Feb 11 23:42:14 2010 -0500
Remove global scoping in CBPurpleOscarAccount.
Each AIHTMLDecoder object is only used in 1 method, so we can scope them within those methods.
diffs (165 lines):
diff -r 522c710857f2 -r bb6ae18089d0 Plugins/Purple Service/CBPurpleOscarAccount.m
--- a/Plugins/Purple Service/CBPurpleOscarAccount.m Thu Feb 11 17:19:04 2010 -0500
+++ b/Plugins/Purple Service/CBPurpleOscarAccount.m Thu Feb 11 23:42:14 2010 -0500
@@ -35,15 +35,10 @@
#import <AIUtilities/AIObjectAdditions.h>
#import <AIUtilities/AIStringAdditions.h>
+#import <libkern/OSAtomic.h>
#define DELAYED_UPDATE_INTERVAL 2.0
-static BOOL createdEncoders = NO;
-static AIHTMLDecoder *encoderCloseFontTagsAttachmentsAsText = nil;
-static AIHTMLDecoder *encoderCloseFontTags = nil;
-static AIHTMLDecoder *encoderAttachmentsAsText = nil;
-static AIHTMLDecoder *encoderGroupChat = nil;
-
@interface CBPurpleOscarAccount ()
- (NSString *)stringByProcessingImgTagsForDirectIM:(NSString *)inString forContactWithUID:(const char *)who;
@end
@@ -56,71 +51,6 @@
return "";
}
-- (void)initAccount
-{
- if (!createdEncoders) {
- encoderCloseFontTagsAttachmentsAsText = [[AIHTMLDecoder alloc] init];
- [encoderCloseFontTagsAttachmentsAsText setIncludesHeaders:YES];
- [encoderCloseFontTagsAttachmentsAsText setIncludesFontTags:YES];
- [encoderCloseFontTagsAttachmentsAsText setClosesFontTags:YES];
- [encoderCloseFontTagsAttachmentsAsText setIncludesStyleTags:YES];
- [encoderCloseFontTagsAttachmentsAsText setIncludesColorTags:YES];
- [encoderCloseFontTagsAttachmentsAsText setEncodesNonASCII:NO];
- [encoderCloseFontTagsAttachmentsAsText setPreservesAllSpaces:NO];
- [encoderCloseFontTagsAttachmentsAsText setUsesAttachmentTextEquivalents:YES];
- [encoderCloseFontTagsAttachmentsAsText setOnlyConvertImageAttachmentsToIMGTagsWhenSendingAMessage:YES];
- [encoderCloseFontTagsAttachmentsAsText setOnlyUsesSimpleTags:NO];
- [encoderCloseFontTagsAttachmentsAsText setAllowAIMsubprofileLinks:YES];
- [encoderCloseFontTagsAttachmentsAsText setAllowJavascriptURLs:YES];
-
- encoderCloseFontTags = [[AIHTMLDecoder alloc] init];
- [encoderCloseFontTags setIncludesHeaders:YES];
- [encoderCloseFontTags setIncludesFontTags:YES];
- [encoderCloseFontTags setClosesFontTags:YES];
- [encoderCloseFontTags setIncludesStyleTags:YES];
- [encoderCloseFontTags setIncludesColorTags:YES];
- [encoderCloseFontTags setEncodesNonASCII:NO];
- [encoderCloseFontTags setPreservesAllSpaces:NO];
- [encoderCloseFontTags setUsesAttachmentTextEquivalents:NO];
- [encoderCloseFontTags setOnlyConvertImageAttachmentsToIMGTagsWhenSendingAMessage:YES];
- [encoderCloseFontTags setOnlyUsesSimpleTags:NO];
- [encoderCloseFontTags setAllowAIMsubprofileLinks:YES];
- [encoderCloseFontTags setAllowJavascriptURLs:YES];
-
- encoderAttachmentsAsText = [[AIHTMLDecoder alloc] init];
- [encoderAttachmentsAsText setIncludesHeaders:YES];
- [encoderAttachmentsAsText setIncludesFontTags:YES];
- [encoderAttachmentsAsText setClosesFontTags:NO];
- [encoderAttachmentsAsText setIncludesStyleTags:YES];
- [encoderAttachmentsAsText setIncludesColorTags:YES];
- [encoderAttachmentsAsText setEncodesNonASCII:NO];
- [encoderAttachmentsAsText setPreservesAllSpaces:NO];
- [encoderAttachmentsAsText setUsesAttachmentTextEquivalents:YES];
- [encoderAttachmentsAsText setOnlyConvertImageAttachmentsToIMGTagsWhenSendingAMessage:YES];
- [encoderAttachmentsAsText setOnlyUsesSimpleTags:NO];
- [encoderAttachmentsAsText setAllowAIMsubprofileLinks:YES];
- [encoderAttachmentsAsText setAllowJavascriptURLs:YES];
-
- encoderGroupChat = [[AIHTMLDecoder alloc] init];
- [encoderGroupChat setIncludesHeaders:NO];
- [encoderGroupChat setIncludesFontTags:YES];
- [encoderGroupChat setClosesFontTags:NO];
- [encoderGroupChat setIncludesStyleTags:YES];
- [encoderGroupChat setIncludesColorTags:YES];
- [encoderGroupChat setEncodesNonASCII:NO];
- [encoderGroupChat setPreservesAllSpaces:NO];
- [encoderGroupChat setUsesAttachmentTextEquivalents:YES];
- [encoderGroupChat setOnlyConvertImageAttachmentsToIMGTagsWhenSendingAMessage:YES];
- [encoderGroupChat setOnlyUsesSimpleTags:YES];
- [encoderGroupChat setAllowAIMsubprofileLinks:YES];
- [encoderGroupChat setAllowJavascriptURLs:YES];
-
- createdEncoders = YES;
- }
-
- [super initAccount];
-}
-
#pragma mark AIListContact and AIService special cases for OSCAR
//Override contactWithUID to mark mobile and ICQ users as such via the displayServiceID
- (AIListContact *)contactWithUID:(NSString *)sourceUID
@@ -451,7 +381,28 @@
}
- (NSString *)encodedAttributedString:(NSAttributedString *)inAttributedString forListObject:(AIListObject *)inListObject
-{
+{
+ static OSSpinLock spinLock = OS_SPINLOCK_INIT;
+ static AIHTMLDecoder * encoderCloseFontTagsAttachmentsAsText = nil;
+
+ OSSpinLockLock(&spinLock);
+ if(!encoderCloseFontTagsAttachmentsAsText) {
+ encoderCloseFontTagsAttachmentsAsText = [[AIHTMLDecoder alloc] initWithHeaders:YES
+ fontTags:YES
+ closeFontTags:YES
+ colorTags:YES
+ styleTags:YES
+ encodeNonASCII:NO
+ encodeSpaces:NO
+ attachmentsAsText:YES
+ onlyIncludeOutgoingImages:YES
+ simpleTagsOnly:NO
+ bodyBackground:NO
+ allowJavascriptURLs:YES];
+ [encoderCloseFontTagsAttachmentsAsText setAllowAIMsubprofileLinks:YES];
+ }
+ OSSpinLockUnlock(&spinLock);
+
return ([inAttributedString length] ? [encoderCloseFontTagsAttachmentsAsText encodeHTML:inAttributedString imagesPath:nil] : nil);
}
@@ -461,6 +412,42 @@
NSAttributedString *inAttributedString = inContentMessage.message;
NSString *encodedString;
+ static OSSpinLock spinLock = OS_SPINLOCK_INIT;
+ static AIHTMLDecoder * encoderCloseFontTags = nil;
+ static AIHTMLDecoder * encoderGroupChat = nil;
+
+ OSSpinLockLock(&spinLock);
+ if(!(encoderCloseFontTags && encoderGroupChat)) {
+ encoderCloseFontTags = [[AIHTMLDecoder alloc] initWithHeaders:YES
+ fontTags:YES
+ closeFontTags:YES
+ colorTags:YES
+ styleTags:YES
+ encodeNonASCII:NO
+ encodeSpaces:NO
+ attachmentsAsText:NO
+ onlyIncludeOutgoingImages:YES
+ simpleTagsOnly:NO
+ bodyBackground:NO
+ allowJavascriptURLs:YES];
+
+ encoderGroupChat = [[AIHTMLDecoder alloc] initWithHeaders:NO
+ fontTags:YES
+ closeFontTags:NO
+ colorTags:YES
+ styleTags:YES
+ encodeNonASCII:NO
+ encodeSpaces:NO
+ attachmentsAsText:YES
+ onlyIncludeOutgoingImages:YES
+ simpleTagsOnly:YES
+ bodyBackground:NO
+ allowJavascriptURLs:YES];
+ [encoderCloseFontTags setAllowAIMsubprofileLinks:YES];
+ [encoderGroupChat setAllowAIMsubprofileLinks:YES];
+ }
+ OSSpinLockUnlock(&spinLock);
+
if (inListObject) {
if (inContentMessage.chat.isSecure &&
oscar_util_valid_name_icq([inContentMessage.source.UID UTF8String]) &&
More information about the commits
mailing list