Skip to content

Comments

refactor: remove unused function and merge duplicated logic#2

Open
tadeubas wants to merge 1 commit intoselfcustody:masterfrom
tadeubas:small_optimizations
Open

refactor: remove unused function and merge duplicated logic#2
tadeubas wants to merge 1 commit intoselfcustody:masterfrom
tadeubas:small_optimizations

Conversation

@tadeubas
Copy link
Member

@tadeubas tadeubas commented Feb 7, 2026

  • Merged duplicate binary-QR condition checks that were spread across two files into a single implementation.
  • Avoided re-checking the input buffer multiple times to detect null bytes.
  • Removed an unused function to reduce total code size.

Includes the commit from this still not merged PR: #1

Tested on Krux with the following code:

from krux.qr import to_qr_codes, FORMAT_NONE
from krux.themes import theme, WHITE
from krux.display import display
from krux.input import Input


qr_foreground = WHITE if theme.bg_color == WHITE else None
inp = Input()

i=0
while True:
    if i == 0:
        data = (i+1)* b"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec lacinia euismod maximus. Aenean luctus condimentum velit. Vivamus posuere ante sed velit interdum, pulvinar pellentesque mi tincidunt. Praesent ut ipsum a dui tincidunt volutpat et eu elit. Sed dolor libero, vestibulum et viverra vel, dictum vel eros. Integer rutrum quis justo vel eleifend. Pellentesque ante erat, suscipit quis neque vitae, efficitur egestas odio. Maecenas dapibus est efficitur, faucibus eros id, dictum sem. In quis imperdiet sem. Quisque vel feugiat ex, nec tempor mauris234562345623456."
    elif i == 1:
        data = b"01234567890123456789"
    elif i == 2:
        data = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
    elif i == 3:
        data = b"ABC\x00DEF"
    elif i == 4:
        data = " woahdi oawij dowaij ,./:[]123! áéíóú àè ìò ù©ç ãẽĩ õũ?"
    elif i == 5:
        data = "" # null
    code_generator = to_qr_codes(data, 999999999, FORMAT_NONE)
    code, num_parts = next(code_generator)

    i += 1
    i = i%6


    # Draw QR code
    if qr_foreground:
        display.draw_qr_code(
            code, light_color=qr_foreground
        )
    else:
        display.draw_qr_code(code)

    inp.wait_for_button(True)

@tadeubas tadeubas force-pushed the small_optimizations branch from b2838d9 to f8b6836 Compare February 10, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant