<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -7,7 +7,7 @@ Author: Hadley Wickham &lt;h.wickham@gmail.com&gt;
 Maintainer: Hadley Wickham &lt;h.wickham@gmail.com&gt;
 Description: profr provides an alternative data structure and visual rendering for the profiling information generated by Rprof.
 URL: http://had.co.nz/profr
-Depends: R (&gt;= 2.6.2)
+Depends: R (&gt;= 2.6.2), digest
 Suggests: ggplot2
 License: MIT
 LazyData: true
\ No newline at end of file</diff>
      <filename>DESCRIPTION</filename>
    </modified>
    <modified>
      <diff>@@ -9,84 +9,75 @@
 # @keyword debugging
 # @value \code{\link{data.frame}} of class \code{profr}
 # @seealso \code{\link{profr}} for profiling and parsing
+#X nesting &lt;- parse_rprof(system.file(&quot;samples&quot;, &quot;nesting.rprof&quot;, &quot;profr&quot;))
+#X diamonds &lt;- parse_rprof(system.file(&quot;samples&quot;, &quot;diamonds.rprof&quot;, &quot;profr&quot;))
 parse_rprof &lt;- function(path, interval=0.02) {
   lines &lt;- scan(path, what=&quot;character&quot;, sep=&quot;\n&quot;)
-	clean.lines &lt;- lines[-grep(&quot;sample\\.interval=&quot;,lines)]
-	calls &lt;- sapply(clean.lines, strsplit, split=&quot; &quot;, USE.NAMES = FALSE)
-	calls &lt;- sapply(calls, rev)
-	calls &lt;- sapply(calls, function(x) gsub(&quot;\&quot;&quot;,&quot;&quot;, x))
-	
-	attr(calls, &quot;interval&quot;) &lt;- interval
-	
-	df &lt;- .simplify_all(.compact(calls))
-	
-	times &lt;- c(&quot;time&quot;, &quot;start&quot;, &quot;end&quot;)
-	df[times] &lt;- df[times] * interval
-	
-	df[c(&quot;f&quot;, &quot;level&quot;, times, &quot;leaf&quot;, &quot;source&quot;)]
+  clean.lines &lt;- lines[-grep(&quot;sample\\.interval=&quot;,lines)]
+  calls &lt;- sapply(clean.lines, strsplit, split=&quot; &quot;, USE.NAMES = FALSE)
+  calls &lt;- sapply(calls, rev)
+  calls &lt;- sapply(calls, function(x) gsub(&quot;\&quot;&quot;,&quot;&quot;, x))
+  
+  df &lt;- .simplify(calls)
+  
+  times &lt;- c(&quot;time&quot;, &quot;start&quot;, &quot;end&quot;)
+  df[times] &lt;- df[times] * interval
+  
+  df[c(&quot;f&quot;, &quot;level&quot;, times, &quot;leaf&quot;, &quot;source&quot;)]
 }
 
-.compact &lt;- function(s, order=TRUE,reverse=FALSE) {
-	.compact.row &lt;- function(s1) data.frame(f=s1$call, level=1:s1$depth, start=s1$start, leaf=1:s1$depth == s1$depth)
+.simplify &lt;- function(calls) {
+  df &lt;- .expand(calls)
+  
+  levels &lt;- split(df, df$level)
+  res &lt;- do.call(rbind, lapply(levels, .collapse_adjacent))
 
-	depth &lt;- sapply(s, length)
-	s &lt;- data.frame(
-		call = array(unclass(s)),
-		start = 0:(length(s)-1),
-		depth = depth
-	)
-	
-	structure(
-		do.call(rbind, apply(s, 1, .compact.row)),
-		interval = attr(s,&quot;interval&quot;)
-	)
+  rownames(res) &lt;- 1:nrow(res)
+  res$time &lt;- res$end - res$start
+  res$source &lt;- .function_sources(res)
+  class(res) &lt;- c(&quot;profr&quot;, &quot;data.frame&quot;)
+  res
 }
 
-.simplify &lt;- function(df) {
+.collapse_adjacent &lt;- function(df) {
   # for each level, want to collapse consecutive of the same function to one
   # provided all previous calls are the same too
-	change &lt;- c(TRUE, (diff(df$start) == 1) &amp; (df$f[-1] != df$f[-nrow(df)]))
-	last_time &lt;- max(df$start) + 1
-	
-	df &lt;- df[change, ]
-	df$time &lt;- diff(c(df$start, last_time))
-	df$end &lt;- df$start + df$time
-
-	df
+  
+  id &lt;- cumsum(c(TRUE, df$hist[-1] != df$hist[-nrow(df)]))
+  groups &lt;- lapply(split(df, id), function(df) {
+    transform(df[1, ], end = max(df$end))
+  })
+  do.call(&quot;rbind&quot;, groups)
 }
 
-.simplify_all &lt;- function(df) {
-	res &lt;- do.call(rbind, 
-		lapply(unique(df$level[df$level &gt; 2] - 2), function(x) .simplify(subset(df, level==x)))
-	)
-	rownames(res) &lt;- 1:nrow(res)
-	res$leaf &lt;- .leaves_all(res)
-	res$source &lt;- .function_sources(res)
-	class(res) &lt;- c(&quot;profr&quot;, &quot;data.frame&quot;)
-	res
+.expand &lt;- function(calls) {
+  .expand.call &lt;- function(s1) with(s1, data.frame(
+    f = call, 
+    level = 1:depth, 
+    start = start, 
+    end = start + 1,
+    leaf = 1:depth == depth,
+    hist = sapply(1:depth, function(i) digest(call[seq_len(i)]))
+  ))
+  
+  depth &lt;- sapply(calls, length)
+  calldf &lt;- data.frame(
+    call = array(unclass(calls)),
+    start = 0:(length(calls)-1),
+    depth = depth
+  )
+  
+  do.call(rbind, apply(calldf, 1, .expand.call))
 }
 
-.leaves &lt;- function(df, x) {
-	lev &lt;- subset(df, level == x)
-
-	!sapply(1:nrow(lev), function(row)  {
-		nrow(.relations(df, lev[row, &quot;start&quot;], lev[row, &quot;end&quot;], x+1)) &gt; 0
-	})
-}
-.leaves_all &lt;- function(df) {
-	unlist(lapply(1:max(df$level), function(x) .leaves(df, x)))
-}
-.relations &lt;- function(df, start, end, levels) {
-	df[df$level %in% levels &amp; df$start &gt;= start &amp; df$end &lt;= end, ]
-}
 
 .function_sources &lt;- function(df) {
-	fs &lt;- sapply(levels(df$f), function(x) do.call(getAnywhere, list(x))$where[1])
-	
-	packaged &lt;- grep(&quot;package&quot;, fs)
-	names &lt;- sapply(strsplit(fs[packaged], &quot;:&quot;), &quot;[&quot;, 2)
+  fs &lt;- sapply(levels(df$f), function(x) do.call(getAnywhere, list(x))$where[1])
+  
+  packaged &lt;- grep(&quot;package&quot;, fs)
+  names &lt;- sapply(strsplit(fs[packaged], &quot;:&quot;), &quot;[&quot;, 2)
   
-	fs[-packaged] &lt;- NA
-	fs[packaged] &lt;- names
-	unname(fs[as.character(df$f)])
+  fs[-packaged] &lt;- NA
+  fs[packaged] &lt;- names
+  unname(fs[as.character(df$f)])
 }
\ No newline at end of file</diff>
      <filename>R/parse.r</filename>
    </modified>
    <modified>
      <diff>@@ -23,4 +23,4 @@ library(reshape)
 Rprof(&quot;diamonds.rprof&quot;)
 dm &lt;- melt(diamonds)
 cast(dm, cut + color + clarity ~ variable, mean)
-Rprof(NULL)
\ No newline at end of file
+Rprof(NULL)</diff>
      <filename>inst/samples/generate.r</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 # library(prof)
+library(digest)
 
 FILE &lt;- (function() {
   attr(body(sys.function()), &quot;srcfile&quot;)</diff>
      <filename>load.r</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>057892c9b6889004f80252f717af0d5fea8f8c3c</id>
    </parent>
  </parents>
  <author>
    <name>hadley</name>
    <email>h.wickham@gmail.com</email>
  </author>
  <url>http://github.com/hadley/profr/commit/37329f45e72a32970fe99b084cd4ea07bfece5cd</url>
  <id>37329f45e72a32970fe99b084cd4ea07bfece5cd</id>
  <committed-date>2008-05-01T17:56:15-07:00</committed-date>
  <authored-date>2008-05-01T17:56:15-07:00</authored-date>
  <message>Rewrite parser.
Improvement correctness and complexity.</message>
  <tree>f3b6e94f9fd120ae43501521f6b5f250707d3512</tree>
  <committer>
    <name>hadley</name>
    <email>h.wickham@gmail.com</email>
  </committer>
</commit>
