<div dir="ltr"><div>Though I'd love to look into the gnome-shell issue more (changing to the overview should not call XIGrabKey/XIUngrabKey a ton of times), the handling in the server here was ridiculous and this is obviously an improvement.<br>
</div><div><br>Reviewed-by: Jasper St. Pierre <<a href="mailto:jstpierre@mecheye.net">jstpierre@mecheye.net</a>><br><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 10, 2013 at 2:18 PM, Adam Jackson <span dir="ltr"><<a href="mailto:ajax@redhat.com" target="_blank">ajax@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">There's no reason to do this as (nmasks + 2) callocs, and it's a<br>
surprisingly hot path. Turns out you hit this ~once per passive grab,<br>
and you do a few bajillion passive grab changes every time you enter or<br>
leave the overview in gnome-shell. According to a callgrind of Xorg<br>
with gnome-shell-perf-tool run against it:<br>
<br>
Ir before: 721437275<br>
Ir after: 454227086<br>
<br>
Signed-off-by: Adam Jackson <<a href="mailto:ajax@redhat.com">ajax@redhat.com</a>><br>
---<br>
dix/inpututils.c | 30 +++++++++++++-----------------<br>
1 file changed, 13 insertions(+), 17 deletions(-)<br>
<br>
diff --git a/dix/inpututils.c b/dix/inpututils.c<br>
index 9e38e17..a10a7c7 100644<br>
--- a/dix/inpututils.c<br>
+++ b/dix/inpututils.c<br>
@@ -960,8 +960,15 @@ XI2Mask *<br>
xi2mask_new_with_size(size_t nmasks, size_t size)<br>
{<br>
int i;<br>
+ int alloc_size;<br>
+ unsigned char *cursor;<br>
+ XI2Mask *mask;<br>
<br>
- XI2Mask *mask = calloc(1, sizeof(*mask));<br>
+ alloc_size = sizeof(struct _XI2Mask)<br>
+ + nmasks * sizeof(unsigned char *)<br>
+ + nmasks * size;<br>
+<br>
+ mask = calloc(1, alloc_size);<br>
<br>
if (!mask)<br>
return NULL;<br>
@@ -969,20 +976,14 @@ xi2mask_new_with_size(size_t nmasks, size_t size)<br>
mask->nmasks = nmasks;<br>
mask->mask_size = size;<br>
<br>
- mask->masks = calloc(mask->nmasks, sizeof(*mask->masks));<br>
- if (!mask->masks)<br>
- goto unwind;<br>
+ mask->masks = (unsigned char **)(mask + 1);<br>
+ cursor = (unsigned char *)(mask + 1) + nmasks * sizeof(unsigned char *);<br>
<br>
- for (i = 0; i < mask->nmasks; i++) {<br>
- mask->masks[i] = calloc(1, mask->mask_size);<br>
- if (!mask->masks[i])<br>
- goto unwind;<br>
+ for (i = 0; i < nmasks; i++) {<br>
+ mask->masks[i] = cursor;<br>
+ cursor += size;<br>
}<br>
return mask;<br>
-<br>
- unwind:<br>
- xi2mask_free(&mask);<br>
- return NULL;<br>
}<br>
<br>
/**<br>
@@ -1003,14 +1004,9 @@ xi2mask_new(void)<br>
void<br>
xi2mask_free(XI2Mask **mask)<br>
{<br>
- int i;<br>
-<br>
if (!(*mask))<br>
return;<br>
<br>
- for (i = 0; (*mask)->masks && i < (*mask)->nmasks; i++)<br>
- free((*mask)->masks[i]);<br>
- free((*mask)->masks);<br>
free((*mask));<br>
*mask = NULL;<br>
}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.1<br>
<br>
_______________________________________________<br>
<a href="mailto:xorg-devel@lists.x.org">xorg-devel@lists.x.org</a>: X.Org development<br>
Archives: <a href="http://lists.x.org/archives/xorg-devel" target="_blank">http://lists.x.org/archives/xorg-devel</a><br>
Info: <a href="http://lists.x.org/mailman/listinfo/xorg-devel" target="_blank">http://lists.x.org/mailman/listinfo/xorg-devel</a><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br> Jasper<br>
</div>