From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CCC2F3858D33; Thu, 1 Feb 2024 12:08:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCC2F3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706789303; bh=wgauaVj8eFcfrSasH/ccBIe+4/KYgobNqODBdfY+X4w=; h=From:To:Subject:Date:From; b=LOV20ij+j4smWfTmPWUmHyE0RM9YO7OfpHwIzz1epwL6chunxTIwqTJkQeeF1AjRX nM3lZF7fd7L2pz0axWikiB03ToV1v948FRjoGVmeWJWoS6Rcsv3sK6ly3LhwPfC2fj sG2E+cfvxER/c/u0m0XdS+Ak6sWpORZOKc1pQ9DY= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/113704] New: std::locale::locale(const locale&, Facet*) is inefficient Date: Thu, 01 Feb 2024 12:08:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.4.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113704 Bug ID: 113704 Summary: std::locale::locale(const locale&, Facet*) is inefficient Product: gcc Version: 11.4.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- template locale:: locale(const locale& __other, _Facet* __f) { _M_impl =3D new _Impl(*__other._M_impl, 1); __try { _M_impl->_M_install_facet(&_Facet::id, __f); } __catch(...) { _M_impl->_M_remove_reference(); __throw_exception_again; } delete [] _M_impl->_M_names[0]; _M_impl->_M_names[0] =3D 0; // Unnamed. } This is very wasteful if the facet isn't already present in __other. First = the _Impl constructor allocates new copies of all the arrays in *__other._M_imp= l, then _M_install_facets reallocates them with additional space for the new facet. We should check whether _Facet::id can be stored without reallocation. If it can't, we should avoid allocating and copying all the arrays twice. This matters for custom user facets which will always have a higher ID and require reallocation.=