Closed Bug 722605 Opened 13 years ago Closed 12 years ago

AndroidGraphicBuffer whitelist uses linear search

Categories

(Firefox for Android Graveyard :: General, defect, P4)

ARM
Android
defect

Tracking

(fennec+)

RESOLVED FIXED
Firefox 28
Tracking Status
fennec + ---

People

(Reporter: snorp, Assigned: tstullich)

References

Details

(Whiteboard: [mentor=snorp][lang=c++])

Attachments

(1 file, 4 obsolete files)

We do a linear search on the whitelist for the device's board name. This could impact startup time if it gets to be too long. We should use a binary search or something similar.
Blocks: 721803
(In reply to Doug Turner (:dougt) from comment #1) > http://mxr.mozilla.org/mozilla-central/source/widget/android/ > AndroidGraphicBuffer.cpp#484 > > Does these have to be exact matches? Uh...yeah, that would probably be more correct.
Assignee: nobody → snorp
tracking-fennec: --- → +
Priority: -- → P4
This bug hasn't moved, so I'm turning it into a mentored bug instead.
Assignee: snorp → nobody
Whiteboard: [mentor=snorp]
Whiteboard: [mentor=snorp] → [mentor=snorp][lang=c++]
Is this bug still available to be taken? If so, I would like to work on it if possible.
Yup. The code that needs to be modified is at http://mxr.mozilla.org/mozilla-central/source/widget/android/AndroidGraphicBuffer.cpp?rev=0f86bf03656b#470. You should start by building Fennec if you haven't done so already; there are instructions at https://wiki.mozilla.org/Mobile/Fennec/Android on how to get set up.
Assignee: nobody → timstullich
Ok, cool. Fennec is being built right now so I have some downtime until it finishes. Maybe I'll get on IRC to get some questions answered in the meantime.
I looked into how I could best implement binary search, but I ran into an issue. I cannot come up with a good way to ensure that I search the left or right subarray after I check whether or not the element exists in the mid point. Is there a way to extract the board name from the device so that I can compare it to the board names on the whitelist?
Flags: needinfo?(snorp)
The best thing here would be to use nsTArray and just use BinaryIndexOf() to find the item. No need to reinvent the wheel :)
Flags: needinfo?(snorp)
OK, that makes sense. I was not aware nsTArray could be used like that. What are some good resources to learn more about the different Classes/Data Structures that are available? I know there are the documentation pages, but if there's something more "noob" friendly that would be great.
(In reply to James Willcox (:snorp) (jwillcox@mozilla.com) from comment #8) > The best thing here would be to use nsTArray and just use BinaryIndexOf() to > find the item. No need to reinvent the wheel :) I think I have come upon a possible solution, although I am not completely sure if it is any good. I constructed an nsTArray with nsAutoString* elements but that feels like an inefficient solution to me since I am manually adding each board name, which takes up too many lines and makes everything really redundant after which I use BinaryIndexOf(). Is there a more elegant solution, that I am not seeing? I have looked through a bunch of the MDN documentation and just can't come up with anything better at the moment.
Attachment #822617 - Flags: review?(timstullich)
Attachment #822617 - Flags: review?(timstullich) → review?(snorp)
Comment on attachment 822617 [details] [diff] [review] Implemented a linear search for the whitelist Review of attachment 822617 [details] [diff] [review]: ----------------------------------------------------------------- Fix the few small issues and then I think we can get this in ::: widget/android/AndroidGraphicBuffer.cpp @@ +449,5 @@ > nullptr > }; > > +// Build whitelist to check for board type. > +static void _initWhiteList(nsTArray<nsString>& list) InitWhiteList @@ +497,5 @@ > LOG("disallowing board '%s' due to prefs override", boardUtf8.get()); > return true; > } > > // FIXME: (Bug 722605) use something better than a linear search You can remove this comment :) @@ +498,5 @@ > return true; > } > > // FIXME: (Bug 722605) use something better than a linear search > + nsTArray<nsString> sListAllowed; You should put this list in a static variable so you only have to initialize it once. @@ +502,5 @@ > + nsTArray<nsString> sListAllowed; > + int i = -1; > + > + _initWhiteList(sListAllowed); > + whitespace
Attachment #822617 - Flags: review?(snorp) → review-
Attachment #822617 - Attachment is obsolete: true
Attachment #822804 - Flags: review?(snorp)
Comment on attachment 822804 [details] [diff] [review] Small fixes made based on first review. Review of attachment 822804 [details] [diff] [review]: ----------------------------------------------------------------- ::: widget/android/AndroidGraphicBuffer.cpp @@ +486,2 @@ > int i = -1; > + InitWhiteList(sListAllowed); You only need to do this once now
Attachment #822804 - Flags: review?(snorp) → review-
(In reply to James Willcox (:snorp) (jwillcox@mozilla.com) from comment #14) > Comment on attachment 822804 [details] [diff] [review] > Small fixes made based on first review. > > Review of attachment 822804 [details] [diff] [review]: > ----------------------------------------------------------------- > > ::: widget/android/AndroidGraphicBuffer.cpp > @@ +486,2 @@ > > int i = -1; > > + InitWhiteList(sListAllowed); > > You only need to do this once now Oh, my mistake. Do you mean something like this static nsTArray<nsString> sListAllowed = InitWhiteList(sListAllowed); ?
Attached patch Fixed static reference issue (obsolete) — Splinter Review
Hopefully this changes the static reference issue. If not, I am not certain how else this issue can be resolved and I would need some further feedback.
Attachment #822804 - Attachment is obsolete: true
Attachment #822811 - Flags: review?(snorp)
Attachment #822811 - Attachment is obsolete: true
Attachment #822811 - Flags: review?(snorp)
Attachment #823496 - Flags: review?(snorp)
Comment on attachment 823496 [details] [diff] [review] The final patch for this bug. Includes all fixes. Review of attachment 823496 [details] [diff] [review]: ----------------------------------------------------------------- Looks good :)
Attachment #823496 - Flags: review?(snorp) → review+
Attachment #823496 - Attachment is obsolete: true
Attachment #823524 - Flags: review?(snorp)
Attachment #823524 - Flags: review?(snorp) → review+
> "omap4sdp" > "SGH-I897" > "sgh-i997" Oughtn't this list be case sensitively sorted? > int i = -1; > if ((i = sListAllowed.BinaryIndexOf(board)) >= 0) { This seems to be a silent cast from unsigned to signed, better to keep it unsigned and compare against NoIndex I guess.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 28
> Oughtn't this list be case sensitively sorted? Ping. Can someone verify that the whitelist still works after this change?
Flags: needinfo?(snorp)
(In reply to Simon Lindholm from comment #24) > > Oughtn't this list be case sensitively sorted? > Ping. Can someone verify that the whitelist still works after this change? I'll look
Flags: needinfo?(snorp)
Any update?
(In reply to Simon Lindholm from comment #26) > Any update? We don't use this code anywhere, so it hasn't been a priority.
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: