iipeace / guider

A Practically Applicable Performance Analyzer for Real Product Development
https://iipeace.github.io/docs/guider.html
GNU General Public License v2.0
629 stars 92 forks source link

Increase the usage of augmented assignment statements #266

Open elfring opened 3 years ago

elfring commented 3 years ago

I suggest to use an augmented assignment statement also at the following place in the function “getData” of the script “guider.py”.

                 # composite packets #
-                data = data + output
+                data += output

                 if not output:
iipeace commented 3 years ago

It looks better! 👍

elfring commented 3 years ago

I propose to reconsider and improve also special string concatenations which can be found with the help of a search pattern like the following.

[Markus_Elfring@fedora guider]$ grep --perl-regexp --count "(\w+)\s*=\s*('|\")%s.*%s.*\2\s*%\s*\(\1,.+\)" guider.py
113

Example:

                         if SysMgr.lineLength > nowLen + len(nextCall):
-                            userCall = '%s%s' % (userCall, nextCall)
+                            userCall += nextCall
                             nowLen += len(nextCall)

Would you like to adjust any more questionable data processing details? :thinking:

iipeace commented 3 years ago

I agree with you! I'll fix them!

elfring commented 3 years ago

Would you like to use any development tools which can help a bit more to perform mass source code transformations? :thinking:

iipeace commented 3 years ago

Yes, I would like to use those tools if I can use them. Could you recommend any tools?

elfring commented 3 years ago
elfring commented 3 years ago

Thanks for another source code improvement.

I guess that there are more remaining update candidates to consider according to the discussed transformation pattern.

Additional change suggestion:

                         else:
-                            userCall = '%s\n%s %s' % \
-                                (userCall, ' ' * indentLen, nextCall)
+                            userCall += '\n%s %s' % (' ' * indentLen, nextCall)
                             nowLen = indentLen + len(nextCall)

Would you find development tools (like the following) helpful?

elfring commented 3 years ago

Yes, I would like to use those tools if I can use them.

Would you like to integrate anything from a source code transformation result which can be generated by a command like the following? (:point_right: Please check also for questionable change suggestions because of an evolving search pattern.)

[Markus_Elfring@fedora lokal]$ ./comby -diff ':[[a]] = :[a] + :[[b]]' ':[a] += :[b]' $(find /home/altes_Heim2/elfring/Projekte/guider/lokal -name '*.py')
iipeace commented 3 years ago

I checked this result :) some lines are wrong but other is useful :)

+++ guider.py
@@ -20727,12 +20727,12 @@
                     data2 = ord(source[count])

                 thisVal = data1*256 + data2
-                sum = sum + thisVal
+                sum += thisVal
                 sum = sum & 0xffffffff # Necessary?
-                count = count + 2
+                count += 2

             if countTo < len(source):
-                sum = sum + ord(source[len(source) - 1])
+                sum += ord(source[len(source) - 1])
                 sum = sum & 0xffffffff # Necessary?

             sum = (sum >> 16)  +  (sum & 0xffff)
@@ -62803,7 +62803,7 @@
                 if sym.endswith(Debugger.RETSTR):
                     rsym = sym
                 else:
-                    rsym = sym + Debugger.RETSTR
+                    rsym += Debugger.RETSTR

                 # add return stats #
                 if rsym in instance.callTable and \
@@ -67605,7 +67605,7 @@
                         struct.unpack('HHHHIII', target)

                     # get verdef strings #
-                    soffset = offset + vd_aux
+                    soffset += vd_aux
                     for vidx in range(vd_cnt):
                         starget = verdef_section[soffset:soffset+sentsize]
                         vda_name, vda_next = \
@@ -67643,7 +67643,7 @@
                         struct.unpack('HHIII', target)

                     # get verneed strings #
-                    soffset = offset + entsize
+                    soffset += entsize
                     for vidx in range(vn_cnt):
                         starget = verneed_section[soffset:soffset+entsize]
                         vna_hash, vna_flags, vna_other, vna_name, vna_next = \
elfring commented 3 years ago

some lines are wrong but other is useful

:thought_balloon: Would you like to integrate anything from a source code transformation result which can be generated also by a command like the following? (:point_right: Update candidates in 26 lines)

[Markus_Elfring@fedora lokal]$ perl -p -i.orig -0777 -e 's/^(?<indentation>\s+)(?<target>\S+)\s*=\s*\k<target>\s*(?<operator>[+\-%&|^@]|\*\*?|\/\/?|<<|>>)/$+{indentation}$+{target} $+{operator}=/gm' $(find /home/altes_Heim2/elfring/Projekte/guider/lokal -name '*.py')
elfring commented 3 years ago

How do you think about to share insights for the evolution of run time characteristics (eventually also for a software component like “Sly Lex Yacc”) together with adjustments for discussed implementation details? :thinking:

elfring commented 3 years ago

:thought_balloon: Do any factors hinder the wider application of functionality which became generally available with Python 2?

iipeace commented 3 years ago

I also like the augmented assignment expression :) I already applied it in manual and using your scripts.