Skip to content

Commit f878453

Browse files
committed
Fix performance issue with RecordCloneCallable
1 parent 4cc9bc9 commit f878453

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

csharp/ql/src/semmle/code/dotnet/Callable.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,25 @@ abstract class Constructor extends Callable { }
9292
/** A destructor/finalizer. */
9393
abstract class Destructor extends Callable { }
9494

95+
pragma[nomagic]
96+
private ValueOrRefType getARecordBaseType(ValueOrRefType t) {
97+
exists(Callable c |
98+
c.hasName("<Clone>$") and
99+
c.getNumberOfParameters() = 0 and
100+
t = c.getDeclaringType() and
101+
result = t
102+
)
103+
or
104+
result = getARecordBaseType(t).getABaseType()
105+
}
106+
95107
/** A clone method on a record. */
96108
class RecordCloneCallable extends Callable {
97109
RecordCloneCallable() {
98110
this.getDeclaringType() instanceof ValueOrRefType and
99111
this.hasName("<Clone>$") and
100112
this.getNumberOfParameters() = 0 and
101-
this.getReturnType() = this.getDeclaringType().(ValueOrRefType).getABaseType*() and
113+
this.getReturnType() = getARecordBaseType(this.getDeclaringType()) and
102114
this.(Member).isPublic() and
103115
not this.(Member).isStatic()
104116
}

0 commit comments

Comments
 (0)