Skip to content

Commit d9c9367

Browse files
authored
core: Reduce calls to THIS wherever possible (gluster#2010)
In few functions 'THIS' is called inside a loop and saved for later use in 'old_THIS'. Instead we can call 'THIS' only when 'old_THIS' is NULL and reuse that itself to reduce redundant calls. Change-Id: Ie5d4e5fe42bd4df02d101b4c199759cb84e6aee1 Fixes: gluster#1755 Signed-off-by: karthik-us <ksubrahm@redhat.com>
1 parent 90f18d1 commit d9c9367

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

heal/src/glfs-heal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,8 @@ glfsh_gather_heal_info(glfs_t *fs, xlator_t *top_subvol, loc_t *rootloc,
11521152
!strstr(xl->name, "-ta-")) {
11531153
heal_xl = _get_ancestor(xl, heal_op);
11541154
if (heal_xl) {
1155-
old_THIS = THIS;
1155+
if (!old_THIS)
1156+
old_THIS = THIS;
11561157
THIS = heal_xl;
11571158
ret = glfsh_print_pending_heals(
11581159
fs, top_subvol, rootloc, xl, heal_op,

libglusterfs/src/fd.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,22 +462,26 @@ fd_destroy(fd_t *fd, gf_boolean_t bound)
462462
for (i = 0; i < fd->xl_count; i++) {
463463
if (fd->_ctx[i].key) {
464464
xl = fd->_ctx[i].xl_key;
465-
old_THIS = THIS;
466-
THIS = xl;
467-
if (!xl->call_cleanup && xl->cbks->releasedir)
465+
if (!xl->call_cleanup && xl->cbks->releasedir) {
466+
if (!old_THIS)
467+
old_THIS = THIS;
468+
THIS = xl;
468469
xl->cbks->releasedir(xl, fd);
469-
THIS = old_THIS;
470+
THIS = old_THIS;
471+
}
470472
}
471473
}
472474
} else {
473475
for (i = 0; i < fd->xl_count; i++) {
474476
if (fd->_ctx[i].key) {
475477
xl = fd->_ctx[i].xl_key;
476-
old_THIS = THIS;
477-
THIS = xl;
478-
if (!xl->call_cleanup && xl->cbks->release)
478+
if (!xl->call_cleanup && xl->cbks->release) {
479+
if (!old_THIS)
480+
old_THIS = THIS;
481+
THIS = xl;
479482
xl->cbks->release(xl, fd);
480-
THIS = old_THIS;
483+
THIS = old_THIS;
484+
}
481485
}
482486
}
483487
}

libglusterfs/src/inode.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ __inode_ctx_free(inode_t *inode)
343343
if (inode->_ctx[index].value1 || inode->_ctx[index].value2) {
344344
xl = (xlator_t *)(long)inode->_ctx[index].xl_key;
345345
if (xl && !xl->call_cleanup && xl->cbks->forget) {
346-
old_THIS = THIS;
346+
if (!old_THIS)
347+
old_THIS = THIS;
347348
THIS = xl;
348349
xl->cbks->forget(xl, inode);
349350
THIS = old_THIS;
@@ -391,11 +392,13 @@ inode_ctx_merge(fd_t *fd, inode_t *inode, inode_t *linked_inode)
391392
if (inode->_ctx[index].xl_key) {
392393
xl = (xlator_t *)(long)inode->_ctx[index].xl_key;
393394

394-
old_THIS = THIS;
395-
THIS = xl;
396-
if (xl->cbks->ictxmerge)
395+
if (xl->cbks->ictxmerge) {
396+
if (!old_THIS)
397+
old_THIS = THIS;
398+
THIS = xl;
397399
xl->cbks->ictxmerge(xl, fd, inode, linked_inode);
398-
THIS = old_THIS;
400+
THIS = old_THIS;
401+
}
399402
}
400403
}
401404
}
@@ -1219,11 +1222,13 @@ inode_invalidate(inode_t *inode)
12191222

12201223
xl = inode->table->xl->graph->first;
12211224
while (xl) {
1222-
old_THIS = THIS;
1223-
THIS = xl;
1224-
if (xl->cbks->invalidate)
1225+
if (xl->cbks->invalidate) {
1226+
if (!old_THIS)
1227+
old_THIS = THIS;
1228+
THIS = xl;
12251229
ret = xl->cbks->invalidate(xl, inode);
1226-
THIS = old_THIS;
1230+
THIS = old_THIS;
1231+
}
12271232

12281233
if (ret)
12291234
break;
@@ -2654,22 +2659,21 @@ inode_ctx_size(inode_t *inode)
26542659
continue;
26552660

26562661
xl = (xlator_t *)(long)inode->_ctx[i].xl_key;
2657-
old_THIS = THIS;
2658-
THIS = xl;
26592662

26602663
/* If inode ref is taken when THIS is global xlator,
26612664
* the ctx xl_key is set, but the value is NULL.
26622665
* For global xlator the cbks can be NULL, hence check
26632666
* for the same */
2664-
if (!xl->cbks) {
2665-
THIS = old_THIS;
2667+
if (!xl->cbks)
26662668
continue;
2667-
}
26682669

2669-
if (xl->cbks->ictxsize)
2670+
if (xl->cbks->ictxsize) {
2671+
if (!old_THIS)
2672+
old_THIS = THIS;
2673+
THIS = xl;
26702674
size += xl->cbks->ictxsize(xl, inode);
2671-
2672-
THIS = old_THIS;
2675+
THIS = old_THIS;
2676+
}
26732677
}
26742678
}
26752679
UNLOCK(&inode->lock);

0 commit comments

Comments
 (0)