[vlc-devel] commit: Skins2: No need to new char[] temporaries; use stack instead. ( JP Dinger )

git version control git at videolan.org
Sat Dec 5 22:35:06 CET 2009


vlc | branch: master | JP Dinger <jpd at videolan.org> | Mon Nov 16 12:56:16 2009 +0100| [d79be0ff4493706827f3fa3d16edd5428ab5093c] | committer: JP Dinger 

Skins2: No need to new char[] temporaries; use stack instead.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d79be0ff4493706827f3fa3d16edd5428ab5093c
---

 modules/gui/skins2/vars/time.cpp |   15 ++++-----------
 1 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/modules/gui/skins2/vars/time.cpp b/modules/gui/skins2/vars/time.cpp
index c0fe90a..536f55d 100644
--- a/modules/gui/skins2/vars/time.cpp
+++ b/modules/gui/skins2/vars/time.cpp
@@ -45,12 +45,9 @@ const string StreamTime::getAsStringPercent() const
 {
     int value = (int)(100. * get());
     // 0 <= value <= 100, so we need 4 chars
-    char *str = new char[4];
+    char str[4];
     snprintf( str, 4, "%d", value );
-    string ret = str;
-    delete[] str;
-
-    return ret;
+    return string(str);
 }
 
 
@@ -121,7 +118,7 @@ const string StreamTime::getAsStringDuration( bool bShortFormat ) const
 
 const string StreamTime::formatTime( int seconds, bool bShortFormat ) const
 {
-    char *psz_time = new char[MSTRTIME_MAX_SIZE];
+    char psz_time[MSTRTIME_MAX_SIZE];
     if( bShortFormat && (seconds < 60 * 60) )
     {
         snprintf( psz_time, MSTRTIME_MAX_SIZE, "%02d:%02d",
@@ -135,9 +132,5 @@ const string StreamTime::formatTime( int seconds, bool bShortFormat ) const
                   (int) (seconds / 60 % 60),
                   (int) (seconds % 60) );
     }
-
-    string ret = psz_time;
-    delete[] psz_time;
-
-    return ret;
+    return string(psz_time);
 }




More information about the vlc-devel mailing list