Use backtick code blocks for syntax highlighting
This commit is contained in:
parent
8ed9dea394
commit
f658bfbb40
203 changed files with 26546 additions and 25801 deletions
56
36-01.md
56
36-01.md
|
|
@ -56,38 +56,42 @@ Second, when performance matters, never have your code perform the same
|
|||
calculation more than once. This sounds obvious, but it's astonishing
|
||||
how often it's ignored. For example, consider this snippet of code:
|
||||
|
||||
for (i=0; i<RunLength; i++)
|
||||
{
|
||||
*WorkingScreenPtr = Color;
|
||||
if (XDelta > 0)
|
||||
{
|
||||
WorkingScreenPtr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
WorkingScreenPtr--;
|
||||
}
|
||||
}
|
||||
```cpp
|
||||
for (i=0; i<RunLength; i++)
|
||||
{
|
||||
*WorkingScreenPtr = Color;
|
||||
if (XDelta > 0)
|
||||
{
|
||||
WorkingScreenPtr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
WorkingScreenPtr--;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Here, the programmer knows which way the line is going before the main
|
||||
loop begins—but nonetheless performs that test every time through the
|
||||
loop, when calculating the address of the next pixel. Far better to
|
||||
perform the test only once, outside the loop, as shown here:
|
||||
|
||||
if (XDelta > 0)
|
||||
{
|
||||
for (i=0; i<RunLength; i++)
|
||||
{
|
||||
*WorkingScreenPtr++ = Color;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<RunLength; i++)
|
||||
{
|
||||
*WorkingScreenPtr-- = Color;
|
||||
}
|
||||
}
|
||||
```cpp
|
||||
if (XDelta > 0)
|
||||
{
|
||||
for (i=0; i<RunLength; i++)
|
||||
{
|
||||
*WorkingScreenPtr++ = Color;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<RunLength; i++)
|
||||
{
|
||||
*WorkingScreenPtr-- = Color;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Think of it this way: A program is a state machine. It takes a set of
|
||||
inputs and produces a corresponding set of outputs by passing through a
|
||||
|
|
|
|||
Loading…
Reference in a new issue