adium 5064:7ec97d2e2160: Replace this usage of OSAtomicCompareAn...

commits at adium.im commits at adium.im
Thu Sep 13 09:16:55 UTC 2012


details:	http://hg.adium.im/adium/rev/7ec97d2e2160
revision:	5064:7ec97d2e2160
branch:		(none)
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Thu Sep 13 11:16:24 2012 +0200

Replace this usage of OSAtomicCompareAndSwapPtrBarrier with dispatch_once, which should be more ARCceptable.

diffs (50 lines):

diff -r fbf9c8679928 -r 7ec97d2e2160 Plugins/Purple Service/CBPurpleOscarAccount.m
--- a/Plugins/Purple Service/CBPurpleOscarAccount.m	Thu Sep 13 11:11:17 2012 +0200
+++ b/Plugins/Purple Service/CBPurpleOscarAccount.m	Thu Sep 13 11:16:24 2012 +0200
@@ -427,26 +427,26 @@
 
 - (NSString *)encodedAttributedString:(NSAttributedString *)inAttributedString forListObject:(AIListObject *)inListObject
 {
-  static AIHTMLDecoder * encoderCloseFontTagsAttachmentsAsText = nil;
-  
-  if(!encoderCloseFontTagsAttachmentsAsText) {
-	AIHTMLDecoder *newEncoder = [[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];
-	OSAtomicCompareAndSwapPtrBarrier(nil, (__bridge void*)newEncoder, (void *)&encoderCloseFontTagsAttachmentsAsText);
-	[encoderCloseFontTagsAttachmentsAsText setAllowAIMsubprofileLinks:YES];
-  }
-  
-  return ([inAttributedString length] ? [encoderCloseFontTagsAttachmentsAsText encodeHTML:inAttributedString imagesPath:nil] : nil);
+	static AIHTMLDecoder *encoderCloseFontTagsAttachmentsAsText = nil;
+	static dispatch_once_t onceToken;
+	
+	dispatch_once(&onceToken, ^{
+		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];
+	});
+	
+	return ([inAttributedString length] ? [encoderCloseFontTagsAttachmentsAsText encodeHTML:inAttributedString imagesPath:nil] : nil);
 }
 
 - (NSString *)encodedAttributedStringForSendingContentMessage:(AIContentMessage *)inContentMessage




More information about the commits mailing list