Just cuz I like doing code reviews, and I figure everyone would love 
some public "best practices" advice:

David Epstein wrote:
> Here's how I use it:
> 
> nsCString theSpec;

use nsCAutoString - see the short mention of stack-based variables in
http://www.mozilla.org/projects/xpcom/string-guide.html#Guidelines

> nsCOMPtr<nsIURI> theURI;
> 
> theSpec = UrlTable[i].theUrl;  // char * url from a table
> rv = NS_NewURI(getter_AddRefs(theURI), theSpec.get());

there's no need to put this into a string object, and then just call 
.get() - this just causes an unnecessary copying of the string.

instead:
rv = NS_NewURI(getter_AddRefs(theURI), UrlTable[i].theUrl);

or, use the nsACString-friendly method (since nsCString/nsCAutoString 
are derived from nsACString)

rv = NS_NewURI(getter_AddRefs(theURI), theSpec);

Alec

> 
> - david
> 
> jianfengguo wrote:
> 
>> Hi,everybody.
>>
>> I am testing GtkMozembed now. Used NS_NewURI api :    nsCAutoString 
>> s(url);   
>>    nsCOMPtr<nsIURI> linkURI;   
>>    NS_NewURI(getter_AddRefs(linkURI), s);  It is right when 
>> compiling.but wrong when linking.
>> Here is link wrong message:
>>    In function 'nsAFlatCString type_info function':
>> 
>/usr/include/mozilla/cpcom/nsIServiceManager.h(.gnu.linkonce.t.__tf14nsAFlatCString+0x11):
> 
>>
>> undefine reference to 'nsASingleFragementCString type_info function'
>> /usr/include/mozilla/xpcom/nsIServiceManager.h(.gnu.linkonce.t.__tf14nsAFlatC 
>> String+0x17):undefined reference to 'nsASingleFragementCString 
>> type_info node'
>>
>>   Could you tell me the wrong reason ?
>>   and tell me how to use NS_NewURI api?
>>    Thanks in advance!
>>  Have a good day!
>>
>>
>>
>>
>>
>>
>>
>> ===================================================================
>> ������ѵ������� (http://mail.sina.com.cn)
>> ���˷�����Ϣ�������г���һ�ߣ��ó���ʱ�ͳ��֣� 
>> (http://classad.sina.com.cn/2shou/)
>>
>>
>>
> 


Reply via email to