Inefficient?

I was just skimming through some of the core libraries looking for something, and I noticed that these two functions seem to be implemented quite inefficiently. I'm wondering if there's something missing here, a reason they're implemented this way.

  <function name="GetBlockingObject" type="object" parameters="obj">
    result = null
    foreach (obj, ListParents(obj)) {
      if (result = null and not CanReachThrough(obj)) {
        result = obj
      }
    }
    return (result)
  </function>

  <function name="ListParents" type="objectlist" parameters="obj">
    <![CDATA[
    result = NewObjectList()
    if (obj.parent <> null) {
      parent_as_list = NewObjectList()
      list add (parent_as_list, obj.parent)
      result = ListCombine(parent_as_list, ListParents(obj.parent))
    }
    return (result)
    ]]>
  </function>

I would have expected to see something like:

  <function name="GetBlockingObject" type="object" parameters="obj">
    obj = object.parent
    while (not obj = null and CanReachThrough (obj)) {
      obj = obj.parent
    }
    return (obj)
  </function>

  <function name="ListParents" type="objectlist" parameters="obj">
    result = NewObjectList()
    while (not obj.parent = null) {
      obj = obj.parent
      list add (result, obj)
    }
    return (result)
  </function>

I think those should be faster than the existing code, and give the same result in all cases. Is there an edge case I'm missing?


No, I think you are right


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums