Merge branch 'joelagnel-for-unique-word-speedup'
diff --git a/trappy/base.py b/trappy/base.py
index 4f2fb21..06857b5 100644
--- a/trappy/base.py
+++ b/trappy/base.py
@@ -180,6 +180,27 @@
         self.line_array.append(line)
         self.data_array.append(data)
 
+    def string_cast(self, string, type):
+        """ Attempt to convert string to another type
+
+        Here we attempt to cast string to a type. Currently only
+        integer conversion is supported with future expansion
+        left open to other types.
+
+        :param string: The value to convert.
+        :type string: str
+
+        :param type: The type to convert to.
+        :type type: type
+        """
+        # Currently this function only supports int conversion
+        if type != int:
+            return
+        # Handle false-positives for negative numbers
+        if not string.lstrip("-").isdigit():
+            return string
+        return int(string)
+
     def generate_data_dict(self, data_str):
         data_dict = {}
         prev_key = None
@@ -191,10 +212,7 @@
                 data_dict[prev_key] += ' ' + field
                 continue
             (key, value) = field.split('=', 1)
-            try:
-                value = int(value)
-            except ValueError:
-                pass
+            value = self.string_cast(value, int)
             data_dict[key] = value
             prev_key = key
         return data_dict
diff --git a/trappy/ftrace.py b/trappy/ftrace.py
index 06e2a93..c0a40c2 100644
--- a/trappy/ftrace.py
+++ b/trappy/ftrace.py
@@ -249,31 +249,27 @@
                 trace_class = DynamicTypeFactory(event_name, (Base,), kwords)
                 self.class_definitions[event_name] = trace_class
 
+    def __get_trace_class(self, line, cls_word):
+        trace_class = None
+        for unique_word, cls in cls_word.iteritems():
+            if unique_word in line:
+                trace_class = cls
+                if not cls.fallback:
+                    return trace_class
+        return trace_class
+
     def __populate_data(self, fin, cls_for_unique_word):
         """Append to trace data from a txt trace"""
 
-        def contains_unique_word(line, unique_words=cls_for_unique_word.keys()):
-            for unique_word in unique_words:
-                if unique_word in line:
-                    return True
-            return False
-
         actual_trace = itertools.dropwhile(self.trace_hasnt_started(), fin)
         actual_trace = itertools.takewhile(self.trace_hasnt_finished(),
                                            actual_trace)
 
         for line in actual_trace:
-            if not contains_unique_word(line):
+            trace_class = self.__get_trace_class(line, cls_for_unique_word)
+            if not trace_class:
                 self.lines += 1
                 continue
-            for unique_word, cls in cls_for_unique_word.iteritems():
-                if unique_word in line:
-                    trace_class = cls
-                    if not cls.fallback:
-                        break
-            else:
-                if not trace_class:
-                    raise FTraceParseError("No unique word in '{}'".format(line))
 
             line = line[:-1]
 
@@ -306,7 +302,8 @@
                 return
 
             # Remove empty arrays from the trace
-            data_str = re.sub(r"[A-Za-z0-9_]+=\{\} ", r"", data_str)
+            if "={}" in data_str:
+                data_str = re.sub(r"[A-Za-z0-9_]+=\{\} ", r"", data_str)
 
             trace_class.append_data(timestamp, comm, pid, cpu, self.lines, data_str)
             self.lines += 1