Closed
Bug 1358007
Opened 8 years ago
Closed 5 years ago
Use nsTArray for Gecko's -moz-border-*-colors storage
Categories
(Core :: CSS Parsing and Computation, enhancement, P3)
Core
CSS Parsing and Computation
Tracking
()
RESOLVED
INVALID
People
(Reporter: chenpighead, Unassigned)
Details
Attachments
(1 file)
|
59 bytes,
text/x-review-board-request
|
Details |
At present, we use double pointers to nsBorderColors to store -moz-border-*-colors. We should be able to use nsTArray instead.
| Comment hidden (mozreview-request) |
| Reporter | ||
Comment 2•8 years ago
|
||
Comment on attachment 8859872 [details]
Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
Hi Ting-Yu, since you always provide great comments while I'm doing refactoring stuff, could you take a look at this and give me some feedbacks? Thanks.
Attachment #8859872 -
Flags: feedback?(tlin)
Comment 3•8 years ago
|
||
| mozreview-review | ||
Comment on attachment 8859872 [details]
Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
https://reviewboard.mozilla.org/r/131848/#review134720
::: layout/style/nsStyleStruct.h:1149
(Diff revision 1)
>
> nsChangeHint CalcDifference(const nsStyleBorder& aNewData) const;
>
> void EnsureBorderColors() {
> - if (!mBorderColors) {
> - mBorderColors = new nsBorderColors*[4];
> + if (mBorderColors.IsEmpty()) {
> + if (mBorderColors.AppendElements(4)) {
We use the magic number 4 in some of the mBorderColor code while some of them iterate by using `mozilla::Side`.
Ideally, we should define `constexpr int eSideCount = 4;` for `Side` like `eCornerCount` [1] for `Corner`, and use it instead of 4. This could be done another followup though.
[1] http://searchfox.org/mozilla-central/rev/d8ac097a1de2544f0e51d186bc850662c5b7430a/gfx/2d/Types.h#417
::: layout/style/nsStyleStruct.h:1268
(Diff revision 1)
> }
> return nullptr;
> }
>
> public:
> - nsBorderColors** mBorderColors; // [reset] composite (stripe) colors
> + nsTArray<nsBorderColors*> mBorderColors; // [reset] composite (stripe) colors
If I'm reading the code correctly, we don't always want to append elements to mBorderColors. We call `EnsureBorderColors()` to allocate needed elements to save memory, so it's OK to use `AppendElements()` in `EnsureBorderColors()` instead of using `AutoTArray<nsBorderColors*, 4>` here.
Comment 4•8 years ago
|
||
Comment on attachment 8859872 [details]
Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
f+ per comment 3.
Attachment #8859872 -
Flags: feedback?(tlin) → feedback+
| Reporter | ||
Comment 5•8 years ago
|
||
| mozreview-review-reply | ||
Comment on attachment 8859872 [details]
Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
https://reviewboard.mozilla.org/r/131848/#review134720
> We use the magic number 4 in some of the mBorderColor code while some of them iterate by using `mozilla::Side`.
>
> Ideally, we should define `constexpr int eSideCount = 4;` for `Side` like `eCornerCount` [1] for `Corner`, and use it instead of 4. This could be done another followup though.
>
> [1] http://searchfox.org/mozilla-central/rev/d8ac097a1de2544f0e51d186bc850662c5b7430a/gfx/2d/Types.h#417
Sounds good to me.
> If I'm reading the code correctly, we don't always want to append elements to mBorderColors. We call `EnsureBorderColors()` to allocate needed elements to save memory, so it's OK to use `AppendElements()` in `EnsureBorderColors()` instead of using `AutoTArray<nsBorderColors*, 4>` here.
Yeah, that's right. Thank you for the feedback. :-)
| Comment hidden (mozreview-request) |
| Reporter | ||
Updated•8 years ago
|
Attachment #8859872 -
Flags: review?(cam)
Comment 7•8 years ago
|
||
| mozreview-review | ||
Comment on attachment 8859872 [details]
Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
https://reviewboard.mozilla.org/r/131848/#review134734
::: commit-message-20dff:3
(Diff revision 2)
> +Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
> +
> +At present, we use double pointers to nsBorderColors (as an 1-D Array)
s/an/a/
::: commit-message-20dff:4
(Diff revision 2)
> +Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
> +
> +At present, we use double pointers to nsBorderColors (as an 1-D Array)
> +to store -moz-border-*-colors. For the simplicity reason, we shall
"For reasons of simplicity" or just "For simplicity"
::: layout/painting/nsCSSRendering.cpp:2041
(Diff revision 2)
> - if (aBorder.mBorderColors)
> + if (!aBorder.mBorderColors.IsEmpty()) {
> return false;
> + }
Is the existing code here wrong? Why isn't it checking whether aBorder.mBorderColors is null (or, in the new code, whether the array is empty), and returning true if so?
::: layout/style/nsStyleStruct.h:1268
(Diff revision 2)
> }
> return nullptr;
> }
>
> public:
> - nsBorderColors** mBorderColors; // [reset] composite (stripe) colors
> + nsTArray<nsBorderColors*> mBorderColors; // [reset] composite (stripe) colors
I think it would be useful to use an nsTArray for the list of border colors for each of the four sides, too, rather than have the manually managed linked list.
(As for the type of the outer array, another option would be to do something like:
typedef mozilla::Array<nsTArray<nscolor>, eSideCount> BorderColors;
UniquePtr<BorderColors> mBorderColors;
That would restrict us to either having mBorderColors be null, or to be a pointer to a fixed-length array of four elements. And it would save us the space of the nsTArray's header. But that doesn't really matter, so I think the nsTArray as you have it is fine.)
WDYT?
| Reporter | ||
Comment 8•8 years ago
|
||
| mozreview-review-reply | ||
Comment on attachment 8859872 [details]
Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
https://reviewboard.mozilla.org/r/131848/#review134734
> Is the existing code here wrong? Why isn't it checking whether aBorder.mBorderColors is null (or, in the new code, whether the array is empty), and returning true if so?
This should've been taken care of in the last line, no?
If aBorder.mBorderColors is null (or, in the new code, whether the array is empty), the existing logic will further check if all four sides are opaque. If all four sides are also opaque, then IsOpaqueBorder() will return true (see the last line of IsOpaqueBorder()).
> I think it would be useful to use an nsTArray for the list of border colors for each of the four sides, too, rather than have the manually managed linked list.
>
> (As for the type of the outer array, another option would be to do something like:
>
> typedef mozilla::Array<nsTArray<nscolor>, eSideCount> BorderColors;
> UniquePtr<BorderColors> mBorderColors;
>
> That would restrict us to either having mBorderColors be null, or to be a pointer to a fixed-length array of four elements. And it would save us the space of the nsTArray's header. But that doesn't really matter, so I think the nsTArray as you have it is fine.)
>
> WDYT?
I like your suggestion. Will fix/write patches accordingly. Thank you.
Comment 9•8 years ago
|
||
| mozreview-review-reply | ||
Comment on attachment 8859872 [details]
Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
https://reviewboard.mozilla.org/r/131848/#review134734
> This should've been taken care of in the last line, no?
>
> If aBorder.mBorderColors is null (or, in the new code, whether the array is empty), the existing logic will further check if all four sides are opaque. If all four sides are also opaque, then IsOpaqueBorder() will return true (see the last line of IsOpaqueBorder()).
But if aBorder.mBorderColors is non-null, that means we might have some border colors specified. I don't think we want to return early in that case, we want to continue and check to see if the colors are opaque. If mBorderColors is null, then we know there are no border colors, and we can return early.
| Reporter | ||
Comment 10•8 years ago
|
||
| mozreview-review-reply | ||
Comment on attachment 8859872 [details]
Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
https://reviewboard.mozilla.org/r/131848/#review134734
> But if aBorder.mBorderColors is non-null, that means we might have some border colors specified. I don't think we want to return early in that case, we want to continue and check to see if the colors are opaque. If mBorderColors is null, then we know there are no border colors, and we can return early.
Oh, I see. So, we might need to further check if there exists at least one -moz-border-*-bolors is non-opaque before return `false`.
Comment 11•8 years ago
|
||
| mozreview-review | ||
Comment on attachment 8859872 [details]
Bug 1358007 - use nsTArray for -moz-border-*-colors storage.
https://reviewboard.mozilla.org/r/131848/#review135494
Cancelling review for now.
Attachment #8859872 -
Flags: review?(cam)
| Reporter | ||
Comment 12•8 years ago
|
||
Busy with stylo, so unassign myself for now.
Assignee: jeremychen → nobody
Status: ASSIGNED → NEW
Updated•8 years ago
|
Priority: -- → P3
Comment 13•5 years ago
|
||
-moz-border-*-colors was removed in bug 1429723.
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•