Update PPC readme. Remove things that are done or aren't ppc specific
[oota-llvm.git] / lib / Support / FileUtilities.cpp
index f8191c51210fb3dd26807b0722c85b71b63f4ee9..6a65ccae3e40e7a3c7caf624b151e7f2f5cff2dc 100644 (file)
@@ -17,6 +17,8 @@
 #include "llvm/System/MappedFile.h"
 #include "llvm/ADT/StringExtras.h"
 #include <cmath>
+#include <cstring>
+#include <cctype>
 using namespace llvm;
 
 static bool isNumberChar(char C) {
@@ -46,6 +48,14 @@ static bool CompareNumbers(char *&F1P, char *&F2P, char *F1End, char *F2End,
                            std::string *ErrorMsg) {
   char *F1NumEnd, *F2NumEnd;
   double V1 = 0.0, V2 = 0.0; 
+
+  // If one of the positions is at a space and the other isn't, chomp up 'til
+  // the end of the space.
+  while (isspace(*F1P) && F1P != F1End)
+    ++F1P;
+  while (isspace(*F2P) && F2P != F2End)
+    ++F2P;
+
   // If we stop on numbers, compare their difference.
   if (isNumberChar(*F1P) && isNumberChar(*F2P)) {
     V1 = strtod(F1P, &F1NumEnd);
@@ -119,7 +129,7 @@ int llvm::DiffFilesWithTolerance(const sys::Path &FileA,
                                  double AbsTol, double RelTol,
                                  std::string *Error) {
   try {
-    // Check for zero length files becasue some systems croak when you try to
+    // Check for zero length files because some systems croak when you try to
     // mmap an empty file.
     size_t A_size = FileA.getSize();
     size_t B_size = FileB.getSize();
@@ -141,19 +151,15 @@ int llvm::DiffFilesWithTolerance(const sys::Path &FileA,
     // Okay, now that we opened the files, scan them for the first difference.
     char *File1Start = F1.charBase();
     char *File2Start = F2.charBase();
-    char *File1End = File1Start+F1.size();
-    char *File2End = File2Start+F2.size();
+    char *File1End = File1Start+A_size;
+    char *File2End = File2Start+B_size;
     char *F1P = File1Start;
     char *F2P = File2Start;
 
     if (A_size == B_size) {
-      // Scan for the end of file or first difference.
-      while (F1P < File1End && F2P < File2End && *F1P == *F2P)
-        ++F1P, ++F2P;
-
-      // Common case: identifical files.
-      if (F1P == File1End && F2P == File2End) 
-        return 0; // Scanned to end, files same
+      // Are the buffers identical?
+      if (std::memcmp(File1Start, File2Start, A_size) == 0)
+        return 0;
 
       if (AbsTol == 0 && RelTol == 0)
         return 1;   // Files different!