Le 11/05/2012 15:01, Roman D. Boiko a écrit :
On Friday, 11 May 2012 at 12:55:58 UTC, Jacob Carlborg wrote:
On 2012-05-11 14:07, Roman D. Boiko wrote:
On Friday, 11 May 2012 at 11:49:23 UTC, Jacob Carlborg wrote:

Found it now, "calculateFor". It not sure if it's the most intuitive
name though. I get the feeling: "calculate what?".

calculateLocation was original name, but I don't like repeating return
type in method names, I decided to change it so that it is clear that
another renaming is needed ;) Any suggestions?


My original suggestion was to have the functionality in Token, which
would have made for intuitive names: line, column and file. But since
you didn't like that I have to give it some thought.

What about the following signature: Location locate(size_t index)?
Or even better:
alias size_t CodeUnitIndex;
Location locateFor(CodeUnitIndex position);

The problem with placing it in Token is that Token should not know
anything about source as a whole.

I don't really see the benefit of this. You are trading a O(1) operation to an O(log(n)) . It can only be faster in specific cases, which should be measured.

It is likely to be slower on compiling erroneous code or used for something else than compiling, and likely to be insignificant to compile correct code (I suspect the performance win is negligible compared to the time required to build a fully operational executable).

You are overcomplicating things for no to little benefice.

Reply via email to