Skip to content

Commit b16086e

Browse files
committed
Make inlinable where possible
1 parent d7bfb7a commit b16086e

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

Sources/SenseHat/SenseHat.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ public class SenseHat {
259259
/// - character: `Character` to be shown on matrix.
260260
/// - color: Boreground color.
261261
/// - background: Background color.
262+
@inlinable
262263
public func show(character: Character, color c: Rgb565, background b: Rgb565 = .black) {
263264
set(data: data(character: character, color: c, background: b))
264265
}
@@ -604,77 +605,100 @@ extension SenseHat {
604605
// Sense Hat uses two bytes per pixel in frame buffer: red, greed and blue
605606
// take respectively 5, 6 and 5 bits.
606607
public struct Rgb565: Equatable {
607-
var value: UInt16
608+
public var value: UInt16
608609

609610
// Red component of color.
610-
var red: UInt8 {
611+
public var red: UInt8 {
612+
@inlinable
611613
get {
612614
UInt8(truncatingIfNeeded: value >> 11)
613615
}
616+
@inlinable
614617
set(newValue) {
615618
value = (value & 0b0000_0111_1111_1111) | (UInt16(newValue) << 11)
616619
}
617620
}
618621

619622
// Green component of color.
620-
var green: UInt8 {
623+
public var green: UInt8 {
624+
@inlinable
621625
get {
622626
UInt8(truncatingIfNeeded: (value & 0b0000_0111_1110_0000) >> 5)
623627
}
628+
@inlinable
624629
set(newValue) {
625630
value = (value & 0b1111_1000_0001_1111) | ((UInt16(newValue) & 0b0011_1111) << 5)
626631
}
627632
}
628633

629634
// Blue component of color.
630-
var blue: UInt8 {
635+
public var blue: UInt8 {
636+
@inlinable
631637
get {
632638
UInt8(truncatingIfNeeded: value) & 0b1_1111
633639
}
640+
@inlinable
634641
set(newValue) {
635642
value = (value & 0b1111_1111_1110_0000) | (UInt16(newValue) & 0b0001_1111)
636643
}
637644
}
638645

646+
@inlinable
639647
init(value: UInt16) {
640648
self.value = value
641649
}
642650

643651
// Black
652+
@inlinable
644653
init() {
645654
self.init(value: 0)
646655
}
647656

657+
@inlinable
648658
init(red: UInt8, green: UInt8, blue: UInt8) {
649659
value = (UInt16(red) << 11) | ((UInt16(green) & 0b0011_1111) << 5) | (UInt16(blue) & 0b0001_1111)
650660
}
651661

662+
@inlinable
652663
public static var red: Rgb565
653664
{ Rgb565(value: 0b1111_1000_0000_0000) }
665+
@inlinable
654666
public static var green: Rgb565
655667
{ Rgb565(value: 0b0000_0111_1110_0000) }
668+
@inlinable
656669
public static var blue: Rgb565
657670
{ Rgb565(value: 0b0000_0000_0001_1111) }
671+
@inlinable
658672
public static var white: Rgb565
659673
{ Rgb565(value: 0b1111_1111_1111_1111) }
674+
@inlinable
660675
public static var black: Rgb565
661676
{ Rgb565(value: 0b0000_0000_0000_0000) }
677+
@inlinable
662678
public static var brown: Rgb565
663679
{ Rgb565(value: 0b1001_1011_0010_0110) } // R:0.6, G:0.4, B:0.2
680+
@inlinable
664681
public static var cyan: Rgb565
665682
{ Rgb565(value: 0b0000_0111_1111_1111) } // R:0.0, G:1.0, B:1.0
683+
@inlinable
666684
public static var magenta: Rgb565
667685
{ Rgb565(value: 0b1111_1000_0001_1111) } // R:1.0, G:0.0, B:1.0
686+
@inlinable
668687
public static var yellow: Rgb565
669688
{ Rgb565(value: 0b1111_1111_1110_0000) } // R:1.0, G:1.0, B:0.0
689+
@inlinable
670690
public static var purple: Rgb565
671691
{ Rgb565(value: 0b1000_0000_0001_0000) } // R:0.5, G:0.0, B:0.5
692+
@inlinable
672693
public static var orange: Rgb565
673694
{ Rgb565(value: 0b1111_1100_0000_0000) } // R:1.0, G:0.5, B:0.0
695+
@inlinable
674696
public static var gray: Rgb565
675697
{ Rgb565(value: 0b1000_0100_0001_0000) } // R:0.5, G:0.5, B:0.5
698+
@inlinable
676699
public static var lightGray: Rgb565
677700
{ Rgb565(value: 0b1010_1101_0101_0101) } // R:2/3, G:2/3, B:2/3
701+
@inlinable
678702
public static var darkGray: Rgb565
679703
{ Rgb565(value: 0b0101_0010_1010_1010) } // R:1/3, G:1/3, B:1/3
680704
}

0 commit comments

Comments
 (0)