Currently I favour to let the shape of the code as it is.

One question arise: Would it make sense to rewrite code like this

[https://github.com/StefanSalewski/RTree/blob/master/rtree.nim#L305](https://github.com/StefanSalewski/RTree/blob/master/rtree.nim#L305)
    
    
    for j in 1 ..< n.numEntries:
      if n of Leaf[M, D, RT, LT]:
        b = union(b, Leaf[M, D, RT, LT](n).a[j].b)
      elif n of Node[M, D, RT, LT]:
        b = union(b, Node[M, D, RT, LT](n).a[j].b)
      else:
        assert false
    

For max speed into something like this:
    
    
    if n of Leaf[M, D, RT, LT]:
      let h = Leaf[M, D, RT, LT](n)
      for j in 1 ..< n.numEntries:
        b = union(b, h.a[j].b)
    elif n of Node[M, D, RT, LT]:
      let h = Node[M, D, RT, LT](n)
      for j in 1 ..< n.numEntries:
        b = union(b, h.a[j].b)
    else:
      assert false
    

Some languages like Oberon had type guards and the with clause for that, I 
think it was code like WITH n:Node[M, D, RT, LT] DO or similar, which saves a 
temporary h pointer. But maybe all that rewriting is unnecessary as the 
compilers optimize it. 

Reply via email to