[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] [cvs2svn] Code cleanup - Use "for: ... else: ..." to avoid a temporary variable

From: Max Bowsher <maxb_at_ukf.net>
Date: 2003-08-23 20:03:09 CEST

mark benedetto king wrote:
> On Sat, Aug 23, 2003 at 11:43:22AM +0100, Max Bowsher wrote:
>> * tools/cvs2svn/cvs2svn.py (SymbolicNameTracker.bump_rev_count):
>> Use "for: ... else: ..." construct to render temporary variable
>> unnecessary.
>>
>> Index: cvs2svn.py
>> ===================================================================
>> --- cvs2svn.py (revision 6839)
>> +++ cvs2svn.py (working copy)
>> @@ -1310,20 +1310,17 @@
>> entry_val[revlist_key] = [(rev, 1)]
>> else:
>> rev_counts = entry_val[revlist_key]
>> - done = None
>> for i in range(len(rev_counts)):
>> this_rev, this_count = rev_counts[i]
>> if rev == this_rev:
>> rev_counts[i] = (this_rev, this_count + 1)
>> - done = 1
>> break
>> elif this_rev > rev:
>> if i > 0:
>> i = i - 1
>> rev_counts.insert(i, (rev, 1))
>> - done = 1
>> break
>> - if not done:
>> + else:
>> rev_counts.append((rev, 1))
>> entry_val[revlist_key] = rev_counts
>>
>
> Doesn't this change the semantics of the block?

No - The behaviour of "for: ... else: ..." is to execute the "else:" unless
the loop was exited by "break".

>
> For example, what if rev_counts contains only pairs of the form (x,y)
> where x < rev?

Then the loop terminates by exhaustion of things to loop over, and executes
the "else:" clause.

Max.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Aug 23 20:35:15 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.