Received: from eggs.gnu.org ([2001:4830:134:3::10]:46746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVwx2-0002Qk-Pm for qemu-devel@nongnu.org; Thu, 12 Mar 2015 02:50:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVwwy-00063l-L1 for qemu-devel@nongnu.org; Thu, 12 Mar 2015 02:50:36 -0400 Message-ID: <55013735.2080305@msgid.tls.msk.ru> Date: Thu, 12 Mar 2015 09:50:29 +0300 From: Michael Tokarev MIME-Version: 1.0 References: <1425503036-23707-1-git-send-email-mjt@msgid.tls.msk.ru> <87k2yorc9q.fsf@linux.vnet.ibm.com> In-Reply-To: <87k2yorc9q.fsf@linux.vnet.ibm.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] 9pfs-local: simplify/optimize local_mapped_attr_path() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Aneesh Kumar K.V" Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org 10.03.2015 20:30, Aneesh Kumar K.V wrote: > Michael Tokarev writes: > >> Omit one unnecessary memory allocation for components of the path >> and create the resulting path directly given lengths of the components. >> >> This uses (char*) cast because basename() accepts a char* without const, >> for unknown reason. Maybe it is better to use strrchr(), but I'm not >> sure for various forms of directory component delimiter. > > basename(3) says: > Both dirname() and basename() may modify the contents of path, so it may > be desirable to pass a copy when calling one of these functions The same manpage also says that there are 2 versions of basename(3), one modifies its arg while another doesn't, and they return different results in some corner cases. Which one will be used depends on the compiler flags. So I think it really is better to open-code it here to have guaranteed consistent results. I'll send a v2. [] > I am not sure whether we really need all these cleanups without really > fixing anyi specific issue. This is not a cleanup, it is an optimization: it removes one completely unnecessary memory allocation. Not in a hottest path but I think it is worth this small effor anyway. Thanks, /mjt