From 97c85e367d7e184ce006f57b0bfc3154a6490716 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Sat, 2 Feb 2002 01:25:57 +0000 Subject: [PATCH] fixes 122892. Optimization Clone of nsLocalFile. Instead of reiniting object, we use default c++ copy construction. r=ccarlen@netscape.com, sr=dveditz@netscape.com --- xpcom/io/nsLocalFileUnix.cpp | 15 +++++++-------- xpcom/io/nsLocalFileWin.cpp | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp index 93336ac5617b..c05b41d50fb4 100644 --- a/xpcom/io/nsLocalFileUnix.cpp +++ b/xpcom/io/nsLocalFileUnix.cpp @@ -240,17 +240,16 @@ nsLocalFile::Clone(nsIFile **file) { CHECK_mPath(); NS_ENSURE_ARG(file); - - nsCOMPtr localFile = new nsLocalFile(); - if (!localFile) - return NS_ERROR_OUT_OF_MEMORY; - - nsresult rv = localFile->InitWithPath(mPath); - if (NS_FAILED(rv)) - return rv; + *file = nsnull; + + // Just copy-construct ourselves + nsCOMPtr localFile = new nsLocalFile(*this); + if (localFile == NULL) + return NS_ERROR_OUT_OF_MEMORY; *file = localFile; NS_ADDREF(*file); + return NS_OK; } diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index 21f96f910d77..c7cf651613c3 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -650,18 +650,18 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal) NS_IMETHODIMP nsLocalFile::Clone(nsIFile **file) { - nsresult rv; + NS_ENSURE_ARG(file); + *file = nsnull; - nsCOMPtr localFile; + // Just copy-construct ourselves + nsCOMPtr localFile = new nsLocalFile(*this); + if (localFile == NULL) + return NS_ERROR_OUT_OF_MEMORY; - rv = NS_NewLocalFile(mWorkingPath.get(), mFollowSymlinks, getter_AddRefs(localFile)); - - if (NS_SUCCEEDED(rv) && localFile) - { - return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)file); - } - - return rv; + *file = localFile; + NS_ADDREF(*file); + + return NS_OK; } NS_IMETHODIMP