Skip to contentSkip to conversation

do nothing if 'current type' == 'the requested type'

PATCH Eric Sandeen 2 participants 2 messages Aug 17, 2020 – Aug 18, 2020 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 19 lines · Jianhong Yin

From: Jianhong Yin <[email protected]>

for power saving and also as a workaround of below issue:

Quoted 2 lines

xfs_db -r /dev/vda3 -c "inode 132" -c "type inode" -c "inode" current inode number is 128

---
 db/type.c | 3 +++
 1 file changed, 3 insertions(+)
db/type.c +0 -0
index 3cb1e868..679de1b0 100644

db/type.c type_f( · line 221

Quoted 9 lines
db/type.c +3 -0
@@ -213,6 +213,9 @@ type_f(
 
 
 	} else {
+		if (cur_typ != NULL && strcmp(cur_typ->name, argv[1]) == 0)
+			return 0;
+
 		tt = findtyp(argv[1]);
 		if (tt == NULL) {
 			dbprintf(_("no such type %s\n"), argv[1]);

Thanks for this - I had a patch on my stack to do the same thing, but did I it this way:

db/type.c +2 -0
index 3cb1e868..5433bcfb 100644
@@ -219,6 +219,8 @@ type_f(
 		} else {
 			if (iocur_top->typ == NULL)
 				dbprintf(_("no current object\n"));
+			else if (iocur_top->typ == tt)
+				return 0;
 			else {
 				cur_typ = tt;
 				set_iocur_type(tt);

which I guess I like a little better than using strcmp on the argument... it compares the type structure directly, rather than comparing the names.

-Eric

#2 lore raw

----- 原始邮件 -----

Quoted 53 lines

发件人: "Eric Sandeen" <[email protected]>
收件人: "Jianhong Yin" <[email protected]>, [email protected]
抄送: "Jianhong Yin" <[email protected]>
发送时间: 星期二, 2020年 8 月 18日 上午 4:33:15
主题: Re: [PATCH] [xfs_db:type] do nothing if 'current type' == 'the requested type'

Quoted 19 lines · Jianhong Yin

From: Jianhong Yin <[email protected]>

for power saving and also as a workaround of below issue:

Quoted 2 lines

xfs_db -r /dev/vda3 -c "inode 132" -c "type inode" -c "inode" current inode number is 128

---
 db/type.c | 3 +++
 1 file changed, 3 insertions(+)
db/type.c +0 -0
index 3cb1e868..679de1b0 100644

db/type.c type_f( · line 221

Quoted 9 lines
db/type.c +3 -0
@@ -213,6 +213,9 @@ type_f(
 
 
 	} else {
+		if (cur_typ != NULL && strcmp(cur_typ->name, argv[1]) == 0)
+			return 0;
+
 		tt = findtyp(argv[1]);
 		if (tt == NULL) {
 			dbprintf(_("no such type %s\n"), argv[1]);

Thanks for this - I had a patch on my stack to do the same thing, but did I it this way:

db/type.c +2 -0
index 3cb1e868..5433bcfb 100644
@@ -219,6 +219,8 @@ type_f(
 		} else {
 			if (iocur_top->typ == NULL)
 				dbprintf(_("no current object\n"));
+			else if (iocur_top->typ == tt)
+				return 0;
 			else {
 				cur_typ = tt;
 				set_iocur_type(tt);
Quoted 2 lines

which I guess I like a little better than using strcmp on the argument... it compares the type structure directly, rather than comparing the names.

Good to know that :)

I just thought that 'tt' is also come from findtyp()->forearch:strcmp(argv,)
and it could save more cpu instructions if compare before findtyp().

but seems I forgot that findtyp() is always needed if curtyp != requested type

"Premature optimization is the root of all evil" ...

Thanks
Jianhong

Quoted 3 lines

-Eric