Code processing method and apparatus

By scanning before and after codebase change operations to identify incremental dead code, the problem of time-consuming and error-prone dead code cleanup in existing technologies is solved, thus achieving efficient codebase maintenance.

CN122111443APending Publication Date: 2026-05-29SHANGHAI BILIBILI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANGHAI BILIBILI TECH CO LTD
Filing Date
2026-02-06
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Existing technologies cannot effectively distinguish and clean up historical legacy code and dead code introduced in the current operation, which requires developers to make manual judgments, which is time-consuming and prone to errors.

Method used

By scanning the target codebase before and after performing changes, a dead code detection tool is used to obtain the baseline and the current set of dead codes. The differences are calculated to identify incremental dead codes, which are then cleaned up.

Benefits of technology

It improves the efficiency of dead code cleanup, avoids the accidental deletion of valuable legacy code, and ensures the robustness of the codebase.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122111443A_ABST
    Figure CN122111443A_ABST
Patent Text Reader

Abstract

The embodiment of the application provides a code processing method, device, computer equipment, computer readable storage medium and computer program product, and belongs to the technical field of software development. The code processing method comprises the following steps: before performing a target change operation on a target code library, scanning the target code library by using a dead code detection tool to obtain a baseline dead code set; in the case that the target change operation on the target code library is completed, scanning the target code library by using the dead code detection tool to obtain a current dead code set, the storage structure of the current dead code set being consistent with the storage structure of the baseline dead code set; determining the difference between the current dead code set and the baseline dead code set, and determining the incremental dead code of the operation based on the difference; and performing invalid code cleaning based on the incremental dead code. The technical scheme of the embodiment of the application can effectively identify the newly added dead code, and improve the efficiency of dead code cleaning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software development technology, and in particular to a code processing method, apparatus, computer device, computer-readable storage medium, and computer program product. Background Technology

[0002] In modern software development, as projects grow in scale and iteration cycles lengthen, codebases accumulate a large amount of dead code. This dead code mainly originates from: old code not deleted after feature iterations, related functions becoming redundant after API interfaces are discontinued, obsolete code generated during code refactoring, and old version adaptation code becoming useless after dependency library upgrades.

[0003] In related technologies, some code analysis tools can be used to analyze and identify uncalled functions; however, these technologies cannot clearly distinguish which dead code is legacy and which is introduced in this operation. Since not all dead code can be directly deleted, developers need to manually determine the source of dead code one by one. The determination process is time-consuming, error-prone, and inefficient.

[0004] It should be noted that the above content is not necessarily prior art, nor is it intended to limit the scope of patent protection of this application. Summary of the Invention

[0005] This application provides a code processing method, apparatus, computer device, computer-readable storage medium, and computer program product to solve or alleviate one or more of the technical problems mentioned above.

[0006] One aspect of this application provides a code processing method, the method comprising:

[0007] Before performing target change operations on the target codebase, the target codebase is scanned using a dead code detection tool to obtain a baseline dead code set; When the target code library is modified, the target code library is scanned using the dead code detection tool to obtain the current dead code set. The storage structure of the current dead code set is consistent with the storage structure of the baseline dead code set. Determine the difference between the current dead code set and the baseline dead code set, and determine the incremental dead code for this operation based on the difference; Invalid code cleanup is performed based on the incremental dead code.

[0008] Optionally, determining the difference between the current dead code set and the baseline dead code set, and determining the incremental dead code for this operation based on the difference, includes: Calculate the difference between the current set of dead codes and the baseline set of dead codes; The difference set is determined as the incremental dead code.

[0009] Optionally, the current dead code set and the baseline dead code set include the file paths of each dead code; The calculation of the difference between the current dead code set and the baseline dead code set includes: Determine whether each file path in the current dead code set exists in the file paths of the baseline dead code set; If the target file path does not exist in the file paths of the baseline dead code set, the dead code corresponding to the target file path is included in the difference set, where the target file path is any file path in the current dead code set.

[0010] Optionally, the method further includes: If the target file path exists in the file path of the baseline dead code set, compare the function names of the current dead code set and the code of the baseline dead code set under the target file path; If the target function name does not exist in the baseline dead code set, the code segment corresponding to the target function name is assigned to the difference set, where the target function name is any function name of the code in the target file path of the current dead code set.

[0011] Optionally, the step of scanning the target codebase using a dead code detection tool to obtain a baseline dead code set includes: The target code library is scanned using the dead code detection tool to obtain the scan results; The scan results are parsed into structured data, the format of which includes file paths and a list of function information; The structured data is stored in a preset format to obtain a baseline dead code set.

[0012] Optionally, the method further includes: If the target codebase receives the target change operation, determine whether the baseline dead code set exists; If the baseline dead code set does not exist, the target change operation is paused, and the step of scanning the target code library using a dead code detection tool to obtain the baseline dead code set is performed.

[0013] Optionally, the dead code detection tool is a dead code detection tool that supports the target programming language, including C, C++, C#, Go, Java, JavaScript, and Python.

[0014] Another aspect of this application provides a code processing apparatus, the apparatus comprising: The first scanning module is used to scan the target code library using a dead code detection tool before performing target change operations on the target code library to obtain a baseline dead code set; The second scanning module is used to scan the target code library using the dead code detection tool when the target change operation is completed on the target code library, to obtain the current dead code set, the storage structure of the current dead code set being consistent with the storage structure of the baseline dead code set; The determination module is used to determine the difference between the current dead code set and the baseline dead code set, and to determine the incremental dead code for this operation based on the difference; The processing module is used to clean up invalid code based on the incremental dead code.

[0015] Another aspect of this application provides a computer device, including: At least one processor; and A memory that is communicatively connected to the at least one processor; Wherein: the memory stores instructions that can be executed by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method as described above.

[0016] Another aspect of this application provides a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the method described above.

[0017] Another aspect of this application provides a computer program product including a computer program that, when executed by a processor, implements the method described above.

[0018] The embodiments of this application employing the above-described technical solution may have the following advantages: Before performing target change operations on the target codebase, a dead code detection tool is used to scan the target codebase to obtain a baseline set of dead code. After the target change operation is performed, the dead code detection tool is used again to scan the target codebase to obtain the current set of dead code. The differences between the current set of dead code and the baseline set of dead code are determined, and the incremental dead code for this operation is identified based on the differences. Invalid code cleanup is performed based on the incremental dead code. This two-stage scanning effectively identifies the newly added dead code. Developers can process only the newly added dead code without checking all dead code, improving the efficiency of dead code cleanup. At the same time, it avoids accidentally deleting other potentially valuable legacy dead code, ensuring the robustness of the target codebase. Attached Figure Description

[0019] The accompanying drawings exemplify embodiments and form part of the specification, serving together with the textual description to explain exemplary implementations of the embodiments. The illustrated embodiments are for illustrative purposes only and do not limit the scope of the claims. Throughout the drawings, the same reference numerals refer to similar but not necessarily identical elements.

[0020] Figure 1 This diagram schematically illustrates the operating environment of the code processing method according to Embodiment 1 of this application; Figure 2 A flowchart illustrating the code processing method according to Embodiment 1 of this application is shown schematically. Figure 3 Schematic illustration Figure 2 Flowchart of the sub-steps in step S204; Figure 4 Schematic illustration Figure 3 Flowchart of the sub-steps in step S300; Figure 5 The illustration shows a new flow in the code processing method according to Embodiment 1 of this application; Figure 6 Schematic illustration Figure 2 Flowchart of the sub-steps in step S200; Figure 7 This illustration schematically shows another additional flow in the code processing method according to Embodiment 1 of this application; Figure 8 A block diagram of a code processing apparatus according to Embodiment 2 of this application is schematically shown; and Figure 9 A schematic diagram of the hardware architecture of a computer device according to Embodiment 3 of this application is shown. Detailed Implementation

[0021] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.

[0022] It should be noted that the descriptions involving "first," "second," etc., in the embodiments of this application are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of that feature. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.

[0023] In the description of this application, it should be understood that the numerical labels before the steps do not indicate the order of the steps, but are only used to facilitate the description of this application and to distinguish each step, and therefore should not be construed as a limitation of this application.

[0024] First, a definition of the terminology used in this application is provided: Dead code: refers to code that will never be executed during program operation.

[0025] Static analysis refers to the method of analyzing a program without running it.

[0026] IDE Integration Inspection: Code analysis functionality integrated within an Integrated Development Environment (IDE).

[0027] Secondly, to facilitate understanding of the technical solutions provided in the embodiments of this application by those skilled in the art, the relevant technologies are described below: In related technologies, the following code analysis tools can be used to identify uncalled functions: 1. One-time batch scanning tools: These tools perform a one-time global scan of the codebase using static analysis methods, identifying uncalled functions by analyzing function calls and variable references. The typical workflow is: scan the entire codebase → generate a list of dead code → manual review → batch deletion. However, these tools cannot identify when the dead code was generated.

[0028] 2. IDE Integration Inspection: This method uses the built-in code analysis features of the integrated development environment (IDE) to perform real-time inspections. As the developer writes code, it identifies unused code elements (such as functions and variables) and provides visual hints (e.g., underlines). However, this method only provides identification and lacks automatic cleanup capabilities.

[0029] 3. Test coverage analysis: This involves running test cases to identify code that is not covered by tests. However, this method can only detect uncovered code and cannot directly determine whether it is dead code.

[0030] The methods described above either fail to identify which code is dead or fail to determine when it was generated. Since not all dead code can be deleted directly, developers need to manually determine the source of each dead code, a process that is time-consuming, error-prone, and inefficient.

[0031] Therefore, this application provides a code processing technical solution. In this solution, before making changes to the target codebase, a dead code detection tool is used to scan the target codebase to obtain a baseline dead code set. After making changes to the target codebase, the same tool is used again to scan the target codebase to obtain the current dead code set. The incremental dead code is determined based on the difference between the current dead code set and the baseline dead code set. Invalid code is then cleaned up based on the incremental dead code. This effectively identifies the newly added dead code, allowing developers to process only the newly added dead code without checking all dead code, thus improving the efficiency of dead code cleanup. Simultaneously, it avoids mistakenly deleting other potentially valuable legacy dead code, ensuring the robustness of the target codebase. See below for details.

[0032] Finally, for ease of understanding, an exemplary operating environment is provided below.

[0033] Figure 1 The illustration shows an environmental application diagram of the method according to an embodiment of this application.

[0034] Computer devices 10000 include various types of electronic devices, such as portable handheld devices, general-purpose computers (such as personal computers and laptops), workstation computers, wearable devices, smart screen devices, self-service terminal devices, service robots, gaming systems, thin clients, various messaging devices, sensors, or other electronic devices. These computer devices can run various types and versions of software applications and operating systems, such as Microsoft Windows, Apple iOS, UNIX-like operating systems, Linux or Linux-like operating systems (such as Google ChromeOS); or include various mobile operating systems, such as Microsoft Windows, Mobile OS, iOS, Windows Phone, and Android. Portable handheld devices can include cellular phones, smartphones, tablets, personal digital assistants, etc. Wearable devices can include head-mounted displays (such as smart glasses). Gaming systems can include various handheld gaming devices, internet-enabled gaming devices, etc. Client devices are capable of executing various applications, such as various internet-related applications, communication applications (such as email applications), short message service (SMS) applications, and can use various communication protocols.

[0035] Computer device 10000 may include input / output interfaces. Input interfaces may include a touchpad, touchscreen, mouse, keyboard, or other sensing elements. Input interfaces can be configured to receive user commands that can cause computer device 10000 to perform various operations, such as commands to modify a target code library. Output interfaces are used to output information to the user, such as displaying information.

[0036] Based on the operating environment described above, computer device 10000 can also have one or more applications installed, such as the application corresponding to the dead code detection tool.

[0037] The technical solutions of this application are described below through several embodiments. It should be understood that these embodiments can be implemented in many different forms and should not be construed as being limited to the embodiments set forth herein.

[0038] Example 1 Figure 2 A flowchart illustrating the code processing method according to Embodiment 1 of this application is shown.

[0039] like Figure 2 As shown, the code processing method may include steps S200~S206, wherein: Step S200: Before performing target change operations on the target code library, the target code library is scanned using a dead code detection tool to obtain a baseline dead code set.

[0040] Step S202: After completing the target change operation on the target code library, the target code library is scanned using a dead code detection tool to obtain the current dead code set. The storage structure of the current dead code set is consistent with the storage structure of the baseline dead code.

[0041] Step S204: Determine the difference between the current dead code set and the baseline dead code set, and determine the incremental dead code for this operation based on the difference.

[0042] Step S206: Clean up invalid code based on incremental dead code.

[0043] The code processing method provided in this embodiment scans the target codebase using a dead code detection tool before performing a target change operation to obtain a baseline dead code set. After the target change operation is completed, the same tool scans the target codebase again to obtain the current dead code set. The differences between the current dead code set and the baseline dead code set are determined, and the incremental dead code for this operation is identified based on these differences. Invalid code cleanup is then performed based on the incremental dead code. This two-stage scanning effectively identifies the newly added dead code, allowing developers to process only the newly added dead code without checking all dead code, thus improving the efficiency of dead code cleanup. Simultaneously, it avoids mistakenly deleting other potentially valuable legacy dead code, ensuring the robustness of the target codebase.

[0044] The following combination Figure 2 The steps in steps S200 to S206, as well as other optional steps, are described in detail.

[0045] Step S200 Before performing target change operations on the target codebase, a dead code detection tool is used to scan the target codebase to obtain a baseline dead code set.

[0046] The target change operations can include operations that modify the target codebase, such as adding, deleting, or modifying API interfaces, refactoring code, and upgrading dependency libraries.

[0047] The timing of the scan can be manually triggered by the developer. For example, if the developer wants to remove a certain API interface from the target codebase, they can manually trigger the scan. Alternatively, the scan can be triggered when a new version of the target codebase is released; the specific timing is not restricted here.

[0048] The dead code detection tool can be a static dead code analysis tool that matches the programming language of the target codebase. For example, if the target codebase is Go, the dead code detection tool can be a static dead code analysis tool corresponding to Go. In an optional embodiment, the dead code detection tool is a dead code detection tool that supports the target programming language, including C, C++, C#, Go, Java, JavaScript, and Python.

[0049] Specifically, before performing target modification operations on the target codebase, a dead code detection tool matching the target codebase's programming language can be invoked to scan the target codebase. Based on the scan results, a baseline dead code set is obtained. For example, a one-time batch scanning tool can be used to scan the target codebase to identify any dead code present. The scan results can be serialized in a preset structured format and stored as a baseline dead code set file. The structured format can be JSON, and may include information such as file paths, function and declaration locations.

[0050] Step S202 When a target code library is modified, a dead code detection tool is used to scan the target code library to obtain the current dead code set. The storage structure of the current dead code set is consistent with the storage structure of the baseline dead code set.

[0051] Specifically, after performing target changes on the target codebase, the target codebase is scanned again using a dead code detection tool. The current dead code set is obtained based on the scan results. The scan results can also be serialized using a preset structure and stored as the current dead code set file, thus ensuring that the storage structure of the current dead code set is consistent with the storage structure of the baseline dead code set.

[0052] Step S204 The difference between the current set of dead codes and the baseline set of dead codes is determined, and the incremental dead codes for this operation are determined based on the difference.

[0053] In optional embodiments, such as Figure 3 As shown, step S204 may further include: Step S300: Calculate the difference between the current dead code set and the baseline dead code set.

[0054] Step S302: Determine the difference set as the incremental dead code.

[0055] Since the baseline dead code set equals the historical dead code set, and the current dead code set equals the historical dead code set plus the new dead code introduced in this operation, we can calculate the difference between the current dead code set and the baseline dead code set to obtain the new dead code introduced in this operation. That is: Current dead code set - Baseline dead code set = Historical dead code + New dead code introduced in this operation - Historical dead code = New dead code introduced in this operation. The new dead code introduced in this operation is also known as the incremental dead code.

[0056] In the embodiments corresponding to steps S300-S302, by calculating the difference between the current dead code set and the baseline dead code set, the difference set is determined as the incremental dead code, which can effectively determine the incremental dead code corresponding to this operation, thereby facilitating the cleanup of newly added dead codes.

[0057] Besides using the set difference method, other methods can be used to determine the difference between the current dead code set and the baseline dead code set. For example, the hash mapping comparison method can be used. The specific method is to first convert the baseline dead code set and the current dead code set into hash dictionaries with the unique identifier of the dead code as the key and the dead code attribute (such as type, path, etc.) as the value. Then, by traversing the keys of the dictionary corresponding to the current dead code set, the elements corresponding to the keys that are not in the dictionary corresponding to the baseline dead code set are filtered out, which are the incremental dead codes of this operation.

[0058] Step S206 Invalid code cleanup is performed based on incremental dead code.

[0059] After obtaining the incremental dead code, it can be directly deleted to clean up invalid code. Since the incremental dead code is only dead code introduced in this operation and its number is small, it can also be submitted to the developers for confirmation, and the finally confirmed incremental dead code can be cleaned up as invalid code. Optionally, a whitelist of dead code can be set up to filter the incremental dead code, excluding the legitimate reserved or compatible code in the whitelist, and the remaining dead code after filtering can be cleaned up as invalid code.

[0060] In an optional embodiment, the current dead code set and the baseline dead code set include the file paths of each dead code. In step S300, the difference between the current dead code set and the baseline dead code set is calculated, such as... Figure 4 As shown, it may include: Step S400: Determine whether each file path in the current dead code set exists in the file paths of the baseline dead code set.

[0061] Step S402: If the target file path does not exist in the file paths of the baseline dead code set, the dead code corresponding to the target file path is assigned to the difference set, and the target file path is any file path in the current dead code set.

[0062] Specifically, each file path in the current dead code set can be traversed, and each file path in the current dead code set can be checked to see if it exists in the file paths of the baseline dead code set. If the target file path in the current dead code set exists in the file paths of the baseline dead code set, it means that the target file path already existed in the first scan, and further judgment is needed to determine whether the dead code in the target file path is incremental dead code. If the target file path in the current dead code set does not exist in the file paths of the baseline dead code set, it means that the code corresponding to the target file path is all newly added dead code, and the dead code corresponding to the target file path is classified into the difference set.

[0063] In this embodiment, by determining whether each file path in the current dead code set exists in the file paths of the baseline dead code set, and in the case that the target file path does not exist in the file paths of the baseline dead code set, the dead code corresponding to the target file path is classified into the difference set. This allows for a file-level comparison between the current dead code set and the baseline dead code set, and the discovery of incremental dead codes at the file level.

[0064] In optional embodiments, such as Figure 5 As shown, the code processing method in this application embodiment may further include: Step S500: If the target file path exists in the file path of the baseline dead code set, compare the function names of the code in the current dead code set and the baseline dead code set under the target file path.

[0065] Step S502: If the target function name does not exist in the baseline dead code set, the code segment corresponding to the target function name is assigned to the difference set. The target function name is any function name of the code in the target file path of the current dead code set.

[0066] Specifically, if the target file path exists in the file path of the baseline dead code set, each function name under the target file path can be traversed, and each function name can be checked one by one to see if it exists in the code under the file path corresponding to the baseline dead code. If the target function name exists in the code under the file path corresponding to the baseline dead code set, it means that the target function name is a legacy dead code. If the target function name does not exist in the code under the file path corresponding to the baseline dead code set, it means that the target function name is an incremental dead code for this operation, and the code segment corresponding to the target function name is assigned to the difference set.

[0067] In practical applications, the line numbers corresponding to function names may change before and after a target change operation. For example, if an import statement is added at the beginning of a file, the line numbers of the original code will shift. In this case, directly comparing the current dead code set with the baseline dead code set using line numbers will lead to misjudgments due to the change in line numbers.

[0068] In this embodiment, when the target file path exists in the file path of the baseline dead code set, the function names of the current dead code set and the baseline dead code in the target file path are compared. When the target function name does not exist in the baseline dead code set, the code segment corresponding to the target function name is assigned to the difference set. This can avoid misjudgment caused by line number changes and accurately determine the incremental dead code.

[0069] In an optional embodiment, in step S200, a dead code detection tool is used to scan the target code library to obtain a baseline dead code set, such as... Figure 6 As shown, it may include: Step S600: Use a dead code detection tool to scan the target code library and obtain the scan results.

[0070] Step S602: Parse the scan results into structured data. The format of the structured data includes file paths and a list of function information.

[0071] Step S604: Store the structured data in a preset format to obtain a baseline dead code set.

[0072] Specifically, a dead code detection tool is used to perform a full scan of the target codebase. Through static analysis or by combining dynamic runtime data, all uncalled code segments without business logic are identified, forming the raw scan results. Next, the unstructured raw scan results are parsed into structured data containing file paths and function information lists. The file paths are used to locate the specific files where the corresponding code segments are located, and the function information lists record attributes such as function names, line numbers, and code types. Finally, the structured data is persisted in a preset format (such as JSON or database table structures) to obtain the baseline dead code set.

[0073] It should be noted that the step S202, which involves scanning the target code library using a dead code detection tool to obtain the current dead code set, can also be implemented using the methods corresponding to steps S600-S604, thereby ensuring that the storage structure of the current dead code set is consistent with the storage structure of the baseline dead code set.

[0074] In this embodiment, the target code library is scanned using a dead code detection tool to obtain the scan results. The scan results are then parsed into structured data, which includes file paths and function information lists. The structured data is stored in a preset format to obtain a baseline dead code set. The scan results can be converted into a standardized format that is machine-recognizable and comparable, facilitating subsequent comparison of the differences between the current dead code set and the baseline dead code set.

[0075] In optional embodiments, such as Figure 7 As shown, the code processing method in this application embodiment may further include: Step S700: If the target code library receives a target change operation, determine whether a set of baseline dead codes exists.

[0076] Step S702: If there is no baseline dead code set, pause the target change operation and perform a scan of the target code library using a dead code detection tool to obtain the baseline dead code set.

[0077] Specifically, methods such as the target code repository's code hosting platform, CI / CD pipeline hooks, or version control plugins can be used to monitor whether the target code repository has received a target change operation. If it is confirmed that the target code repository has received a target change operation, check whether the baseline dead code set already exists in the corresponding storage location of the target code repository. If it exists, allow the target change operation to continue; if it does not exist, immediately pause the execution of the target change operation and output a message indicating that the baseline dead code set does not exist and the operation is not allowed. Then, use a dead code detection tool to scan the target code repository and obtain the baseline dead code set based on the scan results. After obtaining the baseline dead code set, the target change operation can continue, or a message indicating that the target change operation can continue can be output.

[0078] In this embodiment, when a target change operation is received in the target code library, it is determined whether a baseline dead code set exists. If no baseline dead code set exists, the target change operation is paused, and a dead code detection tool is used to scan the target code library to obtain the baseline dead code set. This ensures that subsequent incremental dead code determination has a reliable benchmark and avoids process breaks or invalid analysis caused by the lack of a baseline.

[0079] Example 2 Figure 8The diagram schematically illustrates a code processing apparatus according to Embodiment 2 of this application. This apparatus can be divided into one or more program modules. One or more program modules are stored in a storage medium and executed by one or more processors to complete the embodiments of this application. The program module referred to in the embodiments of this application refers to a series of computer program instruction segments capable of performing a specific function. The following description will specifically introduce the function of each program module in this embodiment. For example... Figure 8 As shown, the device 800 may include: a first scanning module 810, a second scanning module 820, a determining module 830, and a processing module 840, wherein: The first scanning module 810 is used to scan the target code library using a dead code detection tool before performing a target change operation on the target code library to obtain a baseline dead code set; The second scanning module 820 is used to scan the target code library using the dead code detection tool when the target change operation is completed on the target code library, to obtain the current dead code set, wherein the storage structure of the current dead code set is consistent with the storage structure of the baseline dead code set. The determination module 830 is used to determine the difference between the current dead code set and the baseline dead code set, and to determine the incremental dead code for this operation based on the difference; Processing module 840 is used to clean up invalid code based on the incremental dead code.

[0080] In an optional embodiment, the determining module 830 is further configured to: Calculate the difference between the current set of dead codes and the baseline set of dead codes; The difference set is determined as the incremental dead code.

[0081] In an optional embodiment, the current dead code set and the baseline dead code set include the file paths of each dead code; the determining module 830 is further configured to: Determine whether each file path in the current dead code set exists in the file paths of the baseline dead code set; If the target file path does not exist in the file paths of the baseline dead code set, the dead code corresponding to the target file path is included in the difference set, where the target file path is any file path in the current dead code set.

[0082] In an optional embodiment, the device 800 is further used for: If the target file path exists in the file path of the baseline dead code set, compare the function names of the current dead code set and the code of the baseline dead code set under the target file path; If the target function name does not exist in the baseline dead code set, the code segment corresponding to the target function name is assigned to the difference set, where the target function name is any function name of the code in the target file path of the current dead code set.

[0083] In an optional embodiment, the first scanning module 810 is further configured to: The target code library is scanned using the dead code detection tool to obtain the scan results; The scan results are parsed into structured data, the format of which includes file paths and a list of function information; The structured data is stored in a preset format to obtain a baseline dead code set.

[0084] In an optional embodiment, the device 800 is further used for: If the target codebase receives the target change operation, determine whether the baseline dead code set exists; If the baseline dead code set does not exist, the target change operation is paused, and the step of scanning the target code library using a dead code detection tool to obtain the baseline dead code set is performed.

[0085] In an optional embodiment, the dead code detection tool is a dead code detection tool that supports the target programming language, including C, C++, C#, Go, Java, JavaScript, and Python.

[0086] Example 3 Figure 9 This illustration schematically depicts the hardware architecture of a computer device 10000 suitable for implementing a code processing method according to Embodiment 3 of this application. In some embodiments, the computer device 10000 may be a terminal device such as a smartphone, wearable device, tablet computer, personal computer, in-vehicle terminal, game console, virtual device, workbench, digital assistant, set-top box, or robot. In other embodiments, the computer device 10000 may be a rack server, blade server, tower server, or cabinet server (including standalone servers or server clusters composed of multiple servers), etc. Figure 9 As shown, the computer device 10000 includes, but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can communicate and be linked with each other via a system bus. Wherein: The memory 10010 includes at least one type of computer-readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 10010 may be an internal storage module of a computer device 10000, such as the hard disk or memory of the computer device 10000. In other embodiments, the memory 10010 may also be an external storage device of the computer device 10000, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device 10000. Of course, the memory 10010 may also include both the internal storage module and the external storage device of the computer device 10000. In this embodiment, the memory 10010 is typically used to store the operating system and various application software installed on the computer device 10000, such as program code for code processing methods. In addition, the memory 10010 can also be used to temporarily store various types of data that have been output or will be output.

[0087] In some embodiments, processor 10020 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other chip. Processor 10020 is typically used to control the overall operation of computer device 10000, such as performing control and processing related to data interaction or communication with computer device 10000. In this embodiment, processor 10020 is used to run program code stored in memory 10010 or process data.

[0088] Network interface 10030 may include a wireless network interface or a wired network interface, which is typically used to establish a communication link between computer device 10000 and other computer devices. For example, network interface 10030 is used to connect computer device 10000 to an external terminal via a network, establishing a data transmission channel and communication link between computer device 10000 and the external terminal. The network may be an intranet, the Internet, Global System for Mobile Communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, or other wireless or wired networks.

[0089] It should be pointed out that, Figure 9 Only computer devices with components 10010-10030 are shown; however, it should be understood that it is not required to implement all of the shown components, and more or fewer components may be implemented instead.

[0090] In this embodiment, the code processing method stored in memory 10010 can also be divided into one or more program modules and executed by one or more processors (such as processor 10020) to complete the embodiment of this application.

[0091] Example 4 This application also provides a computer-readable storage medium storing a computer program thereon, wherein the computer program, when executed by a processor, implements the steps of the code processing method in the embodiment.

[0092] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the computer-readable storage medium may be an internal storage unit of a computer device, such as the hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device. Of course, the computer-readable storage medium may include both the internal storage unit and the external storage device of the computer device. In this embodiment, the computer-readable storage medium is typically used to store the operating system and various application software installed on the computer device, such as the program code of the code processing method in the embodiment. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or will be output.

[0093] Example 5 This application also provides a computer program product, including a computer program that, when executed by a processor, implements the methods described in the above embodiments.

[0094] Obviously, those skilled in the art should understand that the modules or steps of the embodiments of this application described above can be implemented using general-purpose computer devices. They can be centralized on a single computer device or distributed across a network of multiple computer devices. Optionally, they can be implemented using computer-executable program code, thereby storing them in a storage device for execution by a computer device. In some cases, the steps shown or described can be performed in a different order than those presented here, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the embodiments of this application are not limited to any particular combination of hardware and software.

[0095] It should be noted that the above are merely preferred embodiments of this application and do not limit the scope of patent protection of this application. Any equivalent structural or procedural changes made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of this application.

Claims

1. A code processing method, characterized in that, The method includes: Before performing target change operations on the target codebase, the target codebase is scanned using a dead code detection tool to obtain a baseline dead code set; When the target code library is modified, the target code library is scanned using the dead code detection tool to obtain the current dead code set. The storage structure of the current dead code set is consistent with the storage structure of the baseline dead code set. Determine the difference between the current dead code set and the baseline dead code set, and determine the incremental dead code for this operation based on the difference; Invalid code cleanup is performed based on the incremental dead code.

2. The method according to claim 1, characterized in that, The step of determining the difference between the current dead code set and the baseline dead code set, and determining the incremental dead code for this operation based on the difference, includes: Calculate the difference between the current set of dead codes and the baseline set of dead codes; The difference set is determined as the incremental dead code.

3. The method according to claim 1, characterized in that, The current dead code set and the baseline dead code set include the file paths of each dead code; The calculation of the difference between the current dead code set and the baseline dead code set includes: Determine whether each file path in the current dead code set exists in the file paths of the baseline dead code set; If the target file path does not exist in the file paths of the baseline dead code set, the dead code corresponding to the target file path is included in the difference set, where the target file path is any file path in the current dead code set.

4. The method according to claim 3, characterized in that, The method further includes: If the target file path exists in the file path of the baseline dead code set, compare the function names of the current dead code set and the code of the baseline dead code set under the target file path; If the target function name does not exist in the baseline dead code set, the code segment corresponding to the target function name is assigned to the difference set, where the target function name is any function name of the code in the target file path of the current dead code set.

5. The method according to claim 3, characterized in that, The process of scanning the target codebase using a dead code detection tool to obtain a baseline dead code set includes: The target code library is scanned using the dead code detection tool to obtain the scan results; The scan results are parsed into structured data, the format of which includes file paths and a list of function information; The structured data is stored in a preset format to obtain a baseline dead code set.

6. The method according to claim 1, characterized in that, The method further includes: If the target codebase receives the target change operation, determine whether the baseline dead code set exists; If the baseline dead code set does not exist, the target change operation is paused, and the step of scanning the target code library using a dead code detection tool to obtain the baseline dead code set is performed.

7. The method according to claim 1, characterized in that, The dead code detection tool is a dead code detection tool that supports the target programming language, including C, C++, C#, Go, Java, JavaScript, and Python.

8. A code processing device, characterized in that, The device includes: The first scanning module is used to scan the target code library using a dead code detection tool before performing target change operations on the target code library to obtain a baseline dead code set; The second scanning module is used to scan the target code library using the dead code detection tool when the target change operation is completed on the target code library, to obtain the current dead code set, the storage structure of the current dead code set being consistent with the storage structure of the baseline dead code set; The determination module is used to determine the difference between the current dead code set and the baseline dead code set, and to determine the incremental dead code for this operation based on the difference; The processing module is used to clean up invalid code based on the incremental dead code.

9. A computer device, characterized in that, include: At least one processor; and A memory communicatively connected to the at least one processor; wherein: The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the method as described in any one of claims 1 to 7.

11. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the steps of the method according to any one of claims 1 to 7.