Skip to content

Commit

Permalink
lib/index.js: cache PIN_DEFS.length in PIN_DEFS_LENGTH
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Jun 23, 2017
1 parent 2e7ef8c commit 39bc0a6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ PIN_DEFS.forEach(def => {
}
});

const PIN_DEFS_LENGTH = PIN_DEFS.length;
const PIN_DATA_POOL = Array.from({ length: 20 }, _ => Object.create(null));

const A = "A";
Expand Down Expand Up @@ -169,7 +170,6 @@ const SERVO_MAX = 0.12;

const ADC_RESOLUTION = 4096;


/**
* ToPinIndex Return the board-wide index of a Pin for a given Pin name, Number, or Index
* @param {number} value The index of a pin across port A and B (0-15)
Expand All @@ -182,7 +182,7 @@ function ToPinIndex(value) {
}

if (!Number.isNaN(index)) {
if (index >= 0 && index < PIN_DEFS.length) {
if (index >= 0 && index < PIN_DEFS_LENGTH) {
return index;
} else {
return -1;
Expand Down Expand Up @@ -220,7 +220,7 @@ function ToPortIdentity(index) {
index = +index;
const port = PORTS.BY_NUMBER[index >> 3];

if ((index < 0 || index >= PIN_DEFS.length) ||
if ((index < 0 || index >= PIN_DEFS_LENGTH) ||
port === undefined || PIN_DEFS[index] === undefined) {
return ToPortIdentity.cache.null;
}
Expand Down

0 comments on commit 39bc0a6

Please sign in to comment.