r208783 - Replacing some manual iterations with standard algorithms. No functional changes intended.
David Blaikie
dblaikie at gmail.com
Wed May 14 08:45:59 PDT 2014
On Wed, May 14, 2014 at 8:01 AM, Aaron Ballman <aaron at aaronballman.com> wrote:
> Author: aaronballman
> Date: Wed May 14 10:01:43 2014
> New Revision: 208783
>
> URL: http://llvm.org/viewvc/llvm-project?rev=208783&view=rev
> Log:
> Replacing some manual iterations with standard algorithms. No functional changes intended.
>
> Modified:
> cfe/trunk/lib/Analysis/ThreadSafety.cpp
>
> Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=208783&r1=208782&r2=208783&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
> +++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Wed May 14 10:01:43 2014
> @@ -849,44 +849,37 @@ public:
> return false;
> }
>
> - // Returns an iterator
> iterator findLockIter(FactManager &FM, const SExpr &M) {
> - for (iterator I = begin(), E = end(); I != E; ++I) {
> - const SExpr &Exp = FM[*I].MutID;
> - if (Exp.matches(M))
> - return I;
> - }
> - return end();
> + return std::find_if(begin(), end(), [&FM, &M](FactID ID) {
Opinions differ, but for my money just default capturing by reference
with "[&]" is fine especially for these sort of lambda uses. For
lambdas being squirreled away to live longer than their full
expression, that's different (& then you might want to capture by
value, etc)
- Dave
> + return FM[ID].MutID.matches(M);
> + });
> }
>
> - LockData* findLock(FactManager &FM, const SExpr &M) const {
> - for (const_iterator I = begin(), E = end(); I != E; ++I) {
> - const SExpr &Exp = FM[*I].MutID;
> - if (Exp.matches(M))
> - return &FM[*I].LDat;
> - }
> - return 0;
> - }
> + LockData *findLock(FactManager &FM, const SExpr &M) const {
> + auto I = std::find_if(begin(), end(), [&FM, &M](FactID ID) {
> + return FM[ID].MutID.matches(M);
> + });
>
> - LockData* findLockUniv(FactManager &FM, const SExpr &M) const {
> - for (const_iterator I = begin(), E = end(); I != E; ++I) {
> - const SExpr &Exp = FM[*I].MutID;
> - if (Exp.matches(M) || Exp.isUniversal())
> - return &FM[*I].LDat;
> - }
> - return 0;
> + return I != end() ? &FM[*I].LDat : nullptr;
> }
>
> - FactEntry* findPartialMatch(FactManager &FM, const SExpr &M) const {
> - for (const_iterator I=begin(), E=end(); I != E; ++I) {
> - const SExpr& Exp = FM[*I].MutID;
> - if (Exp.partiallyMatches(M)) return &FM[*I];
> - }
> - return 0;
> + LockData *findLockUniv(FactManager &FM, const SExpr &M) const {
> + auto I = std::find_if(begin(), end(), [&FM, &M](FactID ID) -> bool {
> + const SExpr &Expr = FM[ID].MutID;
> + return Expr.isUniversal() || Expr.matches(M);
> + });
> +
> + return I != end() ? &FM[*I].LDat : nullptr;
> }
> -};
>
> + FactEntry *findPartialMatch(FactManager &FM, const SExpr &M) const {
> + auto I = std::find_if(begin(), end(), [&FM, &M](FactID ID) {
> + return FM[ID].MutID.partiallyMatches(M);
> + });
>
> + return I != end() ? &FM[*I] : nullptr;
> + }
> +};
>
> /// A Lockset maps each SExpr (defined above) to information about how it has
> /// been locked.
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list