[Liblas-commits] hg: Removed cast (r2332) which almost made me collapsing with he...

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Oct 26 18:18:53 EDT 2010


changeset a03892d12365 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=a03892d12365
summary: Removed cast (r2332) which almost made me collapsing with heart attack. Avoid copying std::string unnecessarily.

diffstat:

 apps/laskernel.cpp |  8 ++++----
 apps/laskernel.hpp |  6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diffs (50 lines):

diff -r 34e4e78571a9 -r a03892d12365 apps/laskernel.cpp
--- a/apps/laskernel.cpp	Tue Oct 26 23:05:21 2010 +0100
+++ b/apps/laskernel.cpp	Tue Oct 26 23:18:37 2010 +0100
@@ -1,7 +1,7 @@
 
 #include "laskernel.hpp"
 
-std::istream* OpenInput(std::string filename, bool bEnd) 
+std::istream* OpenInput(std::string const& filename, bool bEnd) 
 {
     std::ios::openmode mode = std::ios::in | std::ios::binary;
     if (bEnd == true) {
@@ -30,10 +30,10 @@
     std::vector<char> data = TryReadRawFileData(filename);
 
     // FIXME: What is this construction supposed to grab? --mloskot
-    return std::string((const char*)data.front(), data.size());
+    return std::string(&data[0], data.size());
 }
 
-std::vector<char> TryReadRawFileData(std::string filename)
+std::vector<char> TryReadRawFileData(std::string const& filename)
 {
     std::istream* infile = OpenInput(filename.c_str(), true);
     std::ifstream::pos_type size;
@@ -63,7 +63,7 @@
     static int lastTick = -1;
     int tick = static_cast<int>(complete * 40.0);
 
-    tick = std::min(40, std::max(0, tick));
+    tick = (std::min)(40, std::max(0, tick));
 
     // Have we started a new progress run?  
     if (tick < lastTick && lastTick >= 39)
diff -r 34e4e78571a9 -r a03892d12365 apps/laskernel.hpp
--- a/apps/laskernel.hpp	Tue Oct 26 23:05:21 2010 +0100
+++ b/apps/laskernel.hpp	Tue Oct 26 23:18:37 2010 +0100
@@ -92,9 +92,9 @@
 #define compare_no_case(a,b,n)  strncasecmp( (a), (b), (n) )
 #endif
 
-std::istream* OpenInput(std::string filename, bool bEnd);
-std::string TryReadFileData(std::string filename);
-std::vector<char> TryReadRawFileData(std::string filename);
+std::istream* OpenInput(std::string const& filename, bool bEnd);
+std::string TryReadFileData(std::string const& filename);
+std::vector<char> TryReadRawFileData(std::string const& filename);
 bool term_progress(std::ostream& os, double complete);
 void SetStreamPrecision(std::ostream& os, double scale);
 


More information about the Liblas-commits mailing list