Index: code/trunk/src/libraries/core/ConfigFileManager.cc
===================================================================
--- code/trunk/src/libraries/core/ConfigFileManager.cc	(revision 6423)
+++ code/trunk/src/libraries/core/ConfigFileManager.cc	(revision 6425)
@@ -58,5 +58,5 @@
     }
 
-    std::string getConfig(const std::string& classname, const std::string& varname)
+    const std::string& getConfig(const std::string& classname, const std::string& varname)
     {
         return ConfigFileManager::getInstance().getValue(ConfigFileType::Settings, classname, varname, "", true);
@@ -94,26 +94,17 @@
     //////////////////////////
 
-    void ConfigFileEntryValue::setValue(const std::string& value)
-    {
-        if (!this->bString_)
-            this->value_ = value;
+    void ConfigFileEntryValue::update()
+    {
+        // Make sure we remove the quotes when bString changes
+        if (this->bString_)
+            this->value_ = stripEnclosingQuotes(this->value_);
+        // Assemble the entry line
+        this->fileEntry_ = this->getKeyString() + " = ";
+        if (this->bString_)
+            this->fileEntry_ += '"' + addSlashes(this->value_) + '"';
         else
-            this->value_ = '"' + addSlashes(stripEnclosingQuotes(value)) + '"';
-    }
-
-    std::string ConfigFileEntryValue::getValue() const
-    {
-        if (!this->bString_)
-            return this->value_;
-        else
-            return removeSlashes(stripEnclosingQuotes(this->value_));
-    }
-
-    std::string ConfigFileEntryValue::getFileEntry() const
-    {
-        if (this->additionalComment_.empty())
-            return (this->name_ + '=' + this->value_);
-        else
-            return (this->name_ + '=' + this->value_ + " " + this->additionalComment_);
+            this->fileEntry_ += this->value_;
+        if (!this->additionalComment_.empty())
+            this->fileEntry_ += ' ' + this->additionalComment_;
     }
 
@@ -122,10 +113,8 @@
     // ConfigFileEntryVectorValue //
     ////////////////////////////////
-    std::string ConfigFileEntryVectorValue::getFileEntry() const
-    {
-        if (this->additionalComment_.empty())
-            return (this->name_ + '[' + multi_cast<std::string>(this->index_) + ']' + '=' + this->value_);
-        else
-            return (this->name_ + '[' + multi_cast<std::string>(this->index_) + "]=" + this->value_ + ' ' + this->additionalComment_);
+    void ConfigFileEntryVectorValue::update()
+    {
+        this->keyString_ = this->name_ + '[' + multi_cast<std::string>(this->index_) + ']';
+        ConfigFileEntryValue::update();
     }
 
Index: code/trunk/src/libraries/core/ConfigFileManager.h
===================================================================
--- code/trunk/src/libraries/core/ConfigFileManager.h	(revision 6423)
+++ code/trunk/src/libraries/core/ConfigFileManager.h	(revision 6425)
@@ -58,5 +58,5 @@
 
     _CoreExport bool config(const std::string& classname, const std::string& varname, const std::string& value); // tolua_export
-    _CoreExport std::string getConfig(const std::string& classname, const std::string& varname); // tolua_export
+    _CoreExport const std::string& getConfig(const std::string& classname, const std::string& varname); // tolua_export
     _CoreExport bool tconfig(const std::string& classname, const std::string& varname, const std::string& value);
     _CoreExport void reloadConfig();
@@ -74,10 +74,10 @@
             virtual ~ConfigFileEntry() {};
             virtual void setValue(const std::string& value) = 0;
-            virtual std::string getValue() const = 0;
+            virtual const std::string& getValue() const = 0;
             virtual const std::string& getName() const = 0;
             virtual void setComment(const std::string& comment) = 0;
             virtual unsigned int getIndex() const { return 0; }
             virtual void setString(bool bString) = 0;
-            virtual std::string getFileEntry() const = 0;
+            virtual const std::string& getFileEntry() const = 0;
     };
 
@@ -94,5 +94,6 @@
                 , bString_(bString)
                 , additionalComment_(additionalComment)
-                {}
+                { this->update(); }
+
             inline virtual ~ConfigFileEntryValue() {}
 
@@ -101,40 +102,55 @@
 
             inline virtual void setComment(const std::string& comment)
-                { this->additionalComment_ = comment; }
-
-            virtual void setValue(const std::string& value);
-            virtual std::string getValue() const;
-
-            inline bool isString() const
-                { return this->bString_; }
-            inline void setString(bool bString)
-                { this->bString_ = bString; }
-
-            virtual std::string getFileEntry() const;
+                { this->additionalComment_ = comment; this->update(); }
+
+            inline virtual void setValue(const std::string& value)
+                { this->value_ = value; this->update(); }
+            inline virtual const std::string& getValue() const
+                { return this->value_; }
+
+            inline void virtual setString(bool bString)
+                { this->bString_ = bString; this->update(); }
+
+            inline virtual const std::string& getFileEntry() const
+                { return this->fileEntry_; }
+
+            inline virtual const std::string& getKeyString() const
+                { return this->name_; }
 
         protected:
-            std::string name_;
+            virtual void update();
+
+            const std::string name_;
             std::string value_;
+            std::string additionalComment_;
+            std::string fileEntry_;
             bool bString_;
-            std::string additionalComment_;
-    };
-
-
-    ///////////////////////////////
+    };
+
+
+    ////////////////////////////////
     // ConfigFileEntryVectorValue //
-    ///////////////////////////////
+    ////////////////////////////////
     class _CoreExport ConfigFileEntryVectorValue : public ConfigFileEntryValue
     {
         public:
-            inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") : ConfigFileEntryValue(name, value, bString, additionalComment), index_(index) {}
-            inline virtual ~ConfigFileEntryVectorValue() {}
-
-            inline virtual unsigned int getIndex() const
+            inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", bool bString = false, const std::string& additionalComment = "")
+                : ConfigFileEntryValue(name, value, bString, additionalComment)
+                , index_(index)
+                { this->update(); /*No virtual calls in base class ctor*/ }
+
+            inline ~ConfigFileEntryVectorValue() {}
+
+            inline unsigned int getIndex() const
                 { return this->index_; }
 
-            virtual std::string getFileEntry() const;
-
-        private:
+            inline const std::string& getKeyString() const
+                { return this->keyString_; }
+
+        private:
+            void update();
+
             unsigned int index_;
+            std::string keyString_;
     };
 
@@ -157,11 +173,15 @@
             inline virtual void setValue(const std::string& value)
                 {}
-            inline virtual std::string getValue() const
+            inline virtual const std::string& getValue() const
+                { return BLANKSTRING; }
+
+            inline void setString(bool bString)
+                {}
+
+            inline virtual const std::string& getFileEntry() const
                 { return this->comment_; }
 
-            inline void setString(bool bString) {}
-
-            inline virtual std::string getFileEntry() const
-                { return this->comment_; }
+            inline virtual const std::string& getKeyString() const
+                { return BLANKSTRING; }
 
         private:
@@ -193,10 +213,10 @@
             inline void setValue(const std::string& name, const std::string& value, bool bString)
                 { this->getEntry(name, value, bString)->setValue(value); }
-            inline std::string getValue(const std::string& name, const std::string& fallback, bool bString)
+            inline const std::string& getValue(const std::string& name, const std::string& fallback, bool bString)
                 { return this->getEntry(name, fallback, bString)->getValue(); }
 
             inline void setValue(const std::string& name, unsigned int index, const std::string& value, bool bString)
                 { this->getEntry(name, index, value, bString)->setValue(value); }
-            inline std::string getValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
+            inline const std::string& getValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
                 { return this->getEntry(name, index, fallback, bString)->getValue(); }
 
@@ -252,10 +272,10 @@
             inline void setValue(const std::string& section, const std::string& name, const std::string& value, bool bString)
                 { this->getSection(section)->setValue(name, value, bString); this->save(); }
-            inline std::string getValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString)
+            inline const std::string& getValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString)
                 { const std::string& output = this->getSection(section)->getValue(name, fallback, bString); this->saveIfUpdated(); return output; }
 
             inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString)
                 { this->getSection(section)->setValue(name, index, value, bString); this->save(); }
-            inline std::string getValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
+            inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
                 { const std::string& output = this->getSection(section)->getValue(name, index, fallback, bString); this->saveIfUpdated(); return output; }
 
@@ -304,10 +324,10 @@
             inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value, bool bString)
                 { this->getFile(type)->setValue(section, name, value, bString); }
-            inline std::string getValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback, bool bString)
+            inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback, bool bString)
                 { return this->getFile(type)->getValue(section, name, fallback, bString); }
 
             inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString)
                 { this->getFile(type)->setValue(section, name, index, value, bString); }
-            inline std::string getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
+            inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
                 { return this->getFile(type)->getValue(section, name, index, fallback, bString); }
 
