-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pocketbook: simplify device model detection #11721
pocketbook: simplify device model detection #11721
Conversation
To avoid avoid having to manually handle the multiple ways a model name reported by inkview can be formatted.
Can it be a hash table instead of many |
-- Pocketbook codenames are all over the place:
local codename = full_codename
-- "PocketBook 615 (PB615)"
codename = codename:match(" [(]([^()]+)[)]$") or codename
-- "PocketBook 615"
codename = codename:match("^PocketBook ([^ ].*)$") or codename
-- "PB615"
codename = codename:match("^PB(.+)$") or codename
local device = ({
["515"] = PocketBook515,
["606"] = PocketBook606,
…
["741"] = PocketBook741,
["743C"] = PocketBook743C,
["743K3"] = PocketBook743K3,
["743G"] = PocketBook743G,
["743g"] = PocketBook743G,
["840"] = PocketBook840,
["Reader InkPad"] = PocketBook840,
["970"] = PocketBook970,
["1040"] = PocketBook1040,
["Color Lux"] = PocketBookColorLux,
})[codename]
if not device then
error("unrecognized PocketBook model " .. full_codename)
end
return device Like this? |
I don't know if I find that nicer than the if/elseif but if other people prefer it I have no objections. |
Hash tables are quicker: https://gammon.com.au/forum/?id=7891 But here we have a one-time operation, so it's not about efficiency, but just readability. Matter of taste, yes.
Without |
You need it to use the table inline, without a temporary assignment. |
Okay, I see the measurement in my link is doubtful. No objections to elseif, of course. |
I see, thanks. |
I think the result is very likely to be the other way around (if/elseif faster) but either way it doesn't matter. |
Following in the footsteps of koreader/koreader#11721
To avoid avoid having to manually handle the multiple ways a model name reported by inkview can be formatted.
Close #11714.
This change is