in reply to Re^3: Need for (XS) speed
in thread Need for (XS) speed
Using SvPVX instead of SvPVbyte makes needless assumptions.
I'm sorry to have to start this all over again, but you are wrong. And here is why you are wrong.
The only thing that it makes sense to pass to a routine expecting a scalar containing a string of packed integers, is exactly that.
Even if it was forced to a PV, because treat that as a C array I'll get garbage.
If it is downgraded to bytes and then I address it as a C array of ints, I'll get garbage.
Treat it as a C int array and I'll get garbage.
The only useful behaviour of those, is the trap. Because it tells me that I haven't passed a packed scalar. Immediately, and unambiguously.
If however, I call SvPVbyte, it won't prevent me from getting a trap if I pass an SV without a PV. But it will turn all the other cases into a piece of memory that there will be no way to discern was not a packed scalar of integers until I start getting garbage results.
And it could take me a long time to trace the source of that garbage back to the error.
The only assumption using SvPVX makes, is that I have passed a properly packed array. And if I haven't, it traps immediately, which tells me exactly where the problem lies.
In other words, the only assumption it makes, is that I know what I'm doing-- and immediately tells me, in no uncertain terms, if I do not.
And that's an invaluable behaviour in any piece of software!
I do not expect you to agree, nor want you to respond.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Need for (XS) speed
by ikegami (Patriarch) on Mar 05, 2010 at 16:24 UTC | |
by BrowserUk (Patriarch) on Mar 05, 2010 at 16:28 UTC | |
by ikegami (Patriarch) on Mar 05, 2010 at 16:47 UTC | |
by BrowserUk (Patriarch) on Mar 05, 2010 at 17:02 UTC | |
by ikegami (Patriarch) on Mar 05, 2010 at 17:08 UTC | |
|