diff --git a/indra/llfilesystem/lldir.cpp b/indra/llfilesystem/lldir.cpp
index 35891d73e8dd2aa46dc7ab813e1f6d6105271ff9..c6ac2ac79e80c4adf1c9a255c7edd82226dcf497 100644
--- a/indra/llfilesystem/lldir.cpp
+++ b/indra/llfilesystem/lldir.cpp
@@ -897,15 +897,15 @@ std::string LLDir::getTempFilename() const
 }
 
 // static
-std::string LLDir::getScrubbedFileName(const std::string uncleanFileName)
+std::string LLDir::getScrubbedFileName(std::string_view uncleanFileName)
 {
     std::string name(uncleanFileName);
     const std::string illegalChars(getForbiddenFileChars());
     // replace any illegal file chars with and underscore '_'
-    for( const char &ch : illegalChars)
+    for (const char& ch : illegalChars)
     {
-        std::string::size_type j = -1;
-        while((j = name.find(ch)) != std::string::npos)
+        std::string::size_type j{ 0 };
+        while ((j = name.find(ch, j)) != std::string::npos)
         {
             name[j] = '_';
         }
diff --git a/indra/llfilesystem/lldir.h b/indra/llfilesystem/lldir.h
index 69794ad458aa82158f384b8e830d4bb72c11661f..c2b63a1b9230b6ef94fe310bf8924ae324c9cbab 100644
--- a/indra/llfilesystem/lldir.h
+++ b/indra/llfilesystem/lldir.h
@@ -180,7 +180,7 @@ class LLDir
     static std::string getDumpLogsDirPath(const std::string &file_name = "");
 
     // For producing safe download file names from potentially unsafe ones
-    static std::string getScrubbedFileName(const std::string uncleanFileName);
+    static std::string getScrubbedFileName(std::string_view uncleanFileName);
     static std::string getForbiddenFileChars();
     void setDumpDir( const std::string& path );