At 9:33am -0400 Mon, 03 Oct 2011, Tor Lillqvist wrote:
stoc/source/inspect/introspection.cxx | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
New commits:
commit 9e6d06a871b366cc72f9a23ab45080b66a47f144
Making my way through a backlog of commits ... it seems to me that it
doesn't matter why the for-loop was used in the first place, because now
it's not "clean" code, and the function could be made "that much better".
I don't know much about the Reference or XIdlClass data types, but this
patch at least compiles on my machine, and I claim removes ambiguity
while remaining true to the "came-before" logic. It also removes the
overhead of recursion, as I don't think this algorithm needs it.
Cheers,
Kevin
>From def7c27b499e0c39ff4ad12637422fd8782b220a Mon Sep 17 00:00:00 2001
From: Kevin Hunter <hunt...@earlham.edu>
Date: Tue, 4 Oct 2011 12:51:10 -0400
Subject: [PATCH] Cleanup isDerivedFrom function
I don't know why it was written previously with a for-loop; my hunch is
that it was originally a mix of thoughts between a recursive and
non-recursive approach. Either way, this could be simplified, so here
is a non-recursive approach. (Why create stack overhead when another
algorithm would suffice?)
This solution also reduces the stack size of the function itself, and
reduces a variable scope.
---
stoc/source/inspect/introspection.cxx | 30 ++++++++----------------------
1 files changed, 8 insertions(+), 22 deletions(-)
diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx
index 36f1acc..831802b 100644
--- a/stoc/source/inspect/introspection.cxx
+++ b/stoc/source/inspect/introspection.cxx
@@ -109,30 +109,16 @@ typedef WeakImplHelper3< XIntrospectionAccess, XMaterialHolder, XExactName > Int
sal_Bool isDerivedFrom( Reference<XIdlClass> xToTestClass, Reference<XIdlClass> xDerivedFromClass )
{
Sequence< Reference<XIdlClass> > aClassesSeq = xToTestClass->getSuperclasses();
- const Reference<XIdlClass>* pClassesArray = aClassesSeq.getConstArray();
- sal_Int32 nSuperClassCount = aClassesSeq.getLength();
- sal_Int32 i;
- for( i = 0 ;
- i < nSuperClassCount ;
- /* No "increment" expression needed as the body always
- * returns, and in fact MSVC warns about unreachable code if
- * we include one. On the other hand, what's the point in
- * using a for loop here then if all we ever will look at is
- * pClassesArray[0] ?
- */ )
- {
- const Reference<XIdlClass>& rxClass = pClassesArray[i];
- if( xDerivedFromClass->equals( rxClass ) )
- {
- // Treffer
+
+ while ( aClassesSeq.getLength() ) {
+ const Reference<XIdlClass>& rxClass = aClassesSeq.getConstArray()[0];
+
+ if ( xDerivedFromClass->equals( rxClass ) )
return sal_True;
- }
- else
- {
- // Rekursiv weitersuchen
- return isDerivedFrom( rxClass, xDerivedFromClass );
- }
+
+ aClassesSeq = rxClass->getSuperclasses();
}
+
return sal_False;
}
--
1.7.1
_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice