Fast alternative to digitalRead/digitalWrite

const static pin_map_t pinMap[] = {
  {&DDRD, &PIND, &PORTD, 0},  // D0  0
  {&DDRD, &PIND, &PORTD, 1},  // D1  1
  {&DDRD, &PIND, &PORTD, 2},  // D2  2
  {&DDRD, &PIND, &PORTD, 3},  // D3  3
  {&DDRD, &PIND, &PORTD, 4},  // D4  4
  {&DDRD, &PIND, &PORTD, 5},  // D5  5

The compiler optimizes const static array accesses to constants? Wow! That makes the earlier attempts at digitalWriteFast look ... silly.

Hmm. With a SLIGHT amount of cooperation from the Arduino core team, the pins_arduino.h file(s) could be set up to generate either the existing PROGMEM tables OR const static arrays, so that "fast" versions of things could be written using exactly the same data used for the slow versions:

const MAYBE_STATIC uint8_t MAYBE_PROGMEM digital_pin_to_port_[] =
{
	PB, /* 0 */
	PB,
	PB,
	PB,
	PB,
//etc

// with:
#define MAYBE_STATIC static
#define MAYBE_PROGMEM
#include <pins_arduino.h>

Or...

#define digital_pin_to_port_M \
{ \
	PB, /* 0 */ \
	PB,\
	PB,\
	PB,\
	PB,\ 
//etc \
}

const uint8_t PROGMEM digital_pin_to_port_PGM[] = digital_pin_to_port_M;
static const uint8_t digital_pin_to_port_S[] = digital_pin_to_port_M;