[haiku-commits] haiku: hrev49078 - src/apps/showimage

  • From: janus2@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 21 Apr 2015 14:52:47 +0200 (CEST)

hrev49078 adds 1 changeset to branch 'master'
old head: e59470891ca8d0bcfccef33d7506a1e533b5e30e
new head: 9c1f5f4d700c419aff4231794fb74e28ff104bf0
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=9c1f5f4d700c+%5Ee59470891ca8

----------------------------------------------------------------------------

9c1f5f4d700c: ShowImage: improve attributes performance.

* Writes the attributes only if they are different or missing.
* Thanks Humdinger for point out.

[ Janus <janus2@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision: hrev49078
Commit: 9c1f5f4d700c419aff4231794fb74e28ff104bf0
URL: http://cgit.haiku-os.org/haiku/commit/?id=9c1f5f4d700c
Author: Janus <janus2@xxxxxxxxx>
Date: Tue Apr 21 12:37:58 2015 UTC

----------------------------------------------------------------------------

1 file changed, 14 insertions(+), 4 deletions(-)
src/apps/showimage/ShowImageWindow.cpp | 18 ++++++++++++++----

----------------------------------------------------------------------------

diff --git a/src/apps/showimage/ShowImageWindow.cpp
b/src/apps/showimage/ShowImageWindow.cpp
index dc843f8..a769fc0 100644
--- a/src/apps/showimage/ShowImageWindow.cpp
+++ b/src/apps/showimage/ShowImageWindow.cpp
@@ -1526,12 +1526,22 @@ ShowImageWindow::_SaveWidthAndHeight()
int32 width = bounds.IntegerWidth() + 1;
int32 height = bounds.IntegerHeight() + 1;

- BFile file(&fNavigator.CurrentRef(), B_WRITE_ONLY);
- if (file.InitCheck() != B_OK)
+ BNode node(&fNavigator.CurrentRef());
+ if (node.InitCheck() != B_OK)
return;

- file.WriteAttr("Media:Width", B_INT32_TYPE, 0, &width, sizeof(width));
- file.WriteAttr("Media:Height", B_INT32_TYPE, 0, &height,
sizeof(height));
+ const char* kWidthAttrName = "Media:Width";
+ const char* kHeightAttrName = "Media:Height";
+
+ int32 widthAttr;
+ ssize_t attrSize = node.ReadAttr(kWidthAttrName, B_INT32_TYPE, 0,
&widthAttr, sizeof(widthAttr));
+ if (attrSize <= 0 || widthAttr != width)
+ node.WriteAttr(kWidthAttrName, B_INT32_TYPE, 0, &width,
sizeof(width));
+
+ int32 heightAttr;
+ attrSize = node.ReadAttr(kHeightAttrName, B_INT32_TYPE, 0, &heightAttr,
sizeof(heightAttr));
+ if (attrSize <= 0 || heightAttr != height)
+ node.WriteAttr(kHeightAttrName, B_INT32_TYPE, 0, &height,
sizeof(height));
}




Other related posts:

  • » [haiku-commits] haiku: hrev49078 - src/apps/showimage - janus2