diff -r c80cf1588ed0 libinterp/corefcn/fcn-info.cc
--- a/libinterp/corefcn/fcn-info.cc	Sat Feb 25 10:28:39 2023 -0500
+++ b/libinterp/corefcn/fcn-info.cc	Sun Feb 26 10:22:20 2023 -0500
@@ -481,7 +481,7 @@ out_of_date_check (octave_value& functio
 
       if (! (fcn->is_subfunction () || fcn->is_anonymous_function ()))
         {
-          std::string ff = fcn->fcn_file_name ();
+          const std::string &ff = fcn->fcn_file_name ();
 
           if (! ff.empty ())
             {
@@ -667,7 +667,7 @@ fcn_info::fcn_info_rep::find_scoped_func
 
       // Local function.
 
-      std::string fcn_file = search_scope.fcn_file_name ();
+      const std::string &fcn_file = search_scope.fcn_file_name ();
 
       // For anonymous functions we look at the parent scope so that if
       // they were defined within class methods and use local functions
@@ -900,7 +900,7 @@ fcn_info::fcn_info_rep::x_builtin_find (
     {
       // Private function.
 
-      std::string dir_name = search_scope.dir_name ();
+      const std::string &dir_name = search_scope.dir_name ();
 
       if (! dir_name.empty ())
         {
@@ -934,7 +934,7 @@ fcn_info::fcn_info_rep::x_builtin_find (
 
       // Local function.
 
-      std::string fcn_file = search_scope.fcn_file_name ();
+      const std::string &fcn_file = search_scope.fcn_file_name ();
 
       if (! fcn_file.empty ())
         {
diff -r c80cf1588ed0 libinterp/corefcn/fcn-info.h
--- a/libinterp/corefcn/fcn-info.h	Sat Feb 25 10:28:39 2023 -0500
+++ b/libinterp/corefcn/fcn-info.h	Sun Feb 26 10:22:20 2023 -0500
@@ -54,7 +54,7 @@ private:
   public:
 
     fcn_info_rep (const std::string& nm)
-      : name (nm), package_name (), local_functions (),
+      : name (nm), package_name (), m_full_name (nm), local_functions (),
         private_functions (), class_constructors (), class_methods (),
         cmdline_function (), autoload_function (), function_on_path (),
         built_in_function ()
@@ -192,18 +192,17 @@ private:
 
     octave_value dump () const;
 
-    std::string full_name () const
+    const std::string& full_name () const
     {
-      if (package_name.empty ())
-        return name;
-      else
-        return package_name + '.' + name;
+      return m_full_name;
     }
 
     std::string name;
 
     std::string package_name;
 
+    std::string m_full_name;
+
     // File name to function object.
     std::map<std::string, octave_value> local_functions;
 
diff -r c80cf1588ed0 libinterp/corefcn/symscope.cc
--- a/libinterp/corefcn/symscope.cc	Sat Feb 25 10:28:39 2023 -0500
+++ b/libinterp/corefcn/symscope.cc	Sun Feb 26 10:22:20 2023 -0500
@@ -387,4 +387,7 @@ std::list<octave_value> symbol_scope::lo
   return ppsr->localfunctions ();
 }
 
+// An empty string object to return const references to
+const std::string symbol_scope::m_empty_string;
+
 OCTAVE_END_NAMESPACE(octave)
diff -r c80cf1588ed0 libinterp/corefcn/symscope.h
--- a/libinterp/corefcn/symscope.h	Sat Feb 25 10:28:39 2023 -0500
+++ b/libinterp/corefcn/symscope.h	Sun Feb 26 10:22:20 2023 -0500
@@ -267,11 +267,11 @@ public:
     m_fcn_file_name = name;
   }
 
-  std::string fcn_file_name () const { return m_fcn_file_name; }
+  const std::string & fcn_file_name () const { return m_fcn_file_name; }
 
   void cache_dir_name (const std::string& name);
 
-  std::string dir_name () const { return m_dir_name; }
+  const std::string & dir_name () const { return m_dir_name; }
 
   void mark_primary_fcn_scope () { m_is_primary_fcn_scope = true; }
 
@@ -626,14 +626,14 @@ public:
       m_rep->cache_dir_name (name);
   }
 
-  std::string fcn_file_name () const
+  const std::string & fcn_file_name () const
   {
-    return m_rep ? m_rep->fcn_file_name () : "";
+    return m_rep ? m_rep->fcn_file_name () : m_empty_string;
   }
 
-  std::string dir_name () const
+  const std::string & dir_name () const
   {
-    return m_rep ? m_rep->dir_name () : "";
+    return m_rep ? m_rep->dir_name () : m_empty_string;
   }
 
   void mark_primary_fcn_scope ()
@@ -718,6 +718,8 @@ public:
   }
 
 private:
+  // An empty string object to return const references to
+  static const std::string m_empty_string;
 
   std::shared_ptr<symbol_scope_rep> m_rep;
 };
