Merge: Optimize nitc
authorJean Privat <jean@pryen.org>
Sat, 7 Mar 2015 05:17:35 +0000 (12:17 +0700)
committerJean Privat <jean@pryen.org>
Sat, 7 Mar 2015 05:17:35 +0000 (12:17 +0700)
Some minor optimizations after looking at reports of valgrind.

Pull-Request: #1191
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/poset.nit
src/astvalidation.nit
src/compiler/abstract_compiler.nit
src/phase.nit

index 93afcf1..3288e5c 100644 (file)
@@ -149,20 +149,37 @@ class POSet[E]
                # Update the transitive reduction
                if te.tos.has(f) then return # Skip the reduction if there is a loop
 
-               for x in te.dfroms.to_a do
+               # Remove transitive edges.
+               # Because the sets of direct is iterated, the list of edges to remove
+               # is stored and is applied after the iteration.
+               # The usual case is that no direct edges need to be removed,
+               # so start with a `null` list of edges.
+               var to_remove: nullable Array[E] = null
+               for x in te.dfroms do
                        var xe = self.elements[x]
                        if xe.tos.has(f) then
-                               te.dfroms.remove(x)
+                               if to_remove == null then to_remove = new Array[E]
+                               to_remove.add x
                                xe.dtos.remove(t)
                        end
                end
-               for x in fe.dtos.to_a do
+               if to_remove != null then
+                       for x in to_remove do te.dfroms.remove(x)
+                       to_remove.clear
+               end
+
+               for x in fe.dtos do
                        var xe = self.elements[x]
                        if xe.froms.has(t) then
                                xe.dfroms.remove(f)
-                               fe.dtos.remove(x)
+                               if to_remove == null then to_remove = new Array[E]
+                               to_remove.add x
                        end
                end
+               if to_remove != null then
+                       for x in to_remove do fe.dtos.remove(x)
+               end
+
                fe.dtos.add t
                te.dfroms.add f
        end
index b568366..b34d42f 100644 (file)
@@ -22,9 +22,7 @@ class ASTValidationVisitor
        super Visitor
        redef fun visit(node)
        do
-               path.unshift(node)
                node.accept_ast_validation(self)
-               path.shift
        end
        private var path = new List[ANode]
        private var seen = new HashSet[ANode]
@@ -34,29 +32,33 @@ redef class ANode
        private fun accept_ast_validation(v: ASTValidationVisitor)
        do
                var parent = self.parent
+               var path = v.path
 
-               if v.path.length > 1 then
-                       var path_parent = v.path[1]
+               if path.length > 0 then
+                       var path_parent = v.path.first
                        if parent == null then
                                self.parent = path_parent
                                #debug "PARENT: expected parent: {path_parent}"
+                               v.seen.add(self)
                        else if parent != path_parent then
                                self.parent = path_parent
-                               debug "PARENT: expected parent: {path_parent}, got {parent}"
+                               if v.seen.has(self) then
+                                       debug "DUPLICATE (NOTATREE): already seen node with parent {parent} now with {path_parent}."
+                               else
+                                       v.seen.add(self)
+                                       debug "PARENT: expected parent: {path_parent}, got {parent}"
+                               end
                        end
                end
 
-               if v.seen.has(self) then
-                       debug "DUPLICATE: already seen node. NOTATREE"
-               end
-               v.seen.add(self)
-
                if not isset _location then
                        #debug "LOCATION: unlocated node {v.path.join(", ")}"
                        _location = self.parent.location
                end
 
+               path.unshift(self)
                visit_all(v)
+               path.shift
        end
 end
 
index b53a7a2..23927b6 100644 (file)
@@ -2304,7 +2304,7 @@ redef class AAttrPropdef
 
        fun init_expr(v: AbstractCompilerVisitor, recv: RuntimeVariable)
        do
-               if has_value and not is_lazy then evaluate_expr(v, recv)
+               if has_value and not is_lazy and not n_expr isa ANullExpr then evaluate_expr(v, recv)
        end
 
        # Evaluate, store and return the default value of the attribute
index 0a32484..bdec532 100644 (file)
@@ -110,7 +110,6 @@ redef class ToolContext
 
                        for phase in phases do
                                if phase.disabled then continue
-                               self.info(" phase: {phase}", 3)
                                assert phase.toolcontext == self
                                var errcount = self.error_count
                                phase.process_nmodule(nmodule)