Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize code size for text-utils.ts #18262

Open
wants to merge 2 commits into
base: v3.8.6
Choose a base branch
from

Conversation

dumganhar
Copy link
Contributor

@dumganhar dumganhar commented Jan 29, 2025

Re: #18222

截屏2025-01-29 23 08 22
function regexEqual(regex1, regex2) {
    return regex1.source === regex2.source && regex1.flags === regex2.flags;
}


LAST_WORD_REG = /([a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłę湯ŹŚÓŃŁĘĆĄ-яА-ЯЁёáàãăâéèêếiíìĩóòõôơúùũưýđÁÀÃĂÂÉÈÊIÍÌĨÓÒÕÔƠÚÙŨƯÝĐ]+|\S)$/;
LAST_ENGLISH_REG = /[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłę湯ŹŚÓŃŁĘĆĄ-яА-ЯЁёáàãăâéèêếiíìĩóòõôơúùũưýđÁÀÃĂÂÉÈÊIÍÌĨÓÒÕÔƠÚÙŨƯÝĐ]+$/;
FIRST_ENGLISH_REG = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłę湯ŹŚÓŃŁĘĆĄ-яА-ЯЁёáàãăâéèêếiíìĩóòõôơúùũưýđÁÀÃĂÂÉÈÊIÍÌĨÓÒÕÔƠÚÙŨƯÝĐ]/;

CHAR_SET = '[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłę湯ŹŚÓŃŁĘĆĄ-яА-ЯЁёáàảạãăắằẳẵặâấầẩẫậéèẻẽẹêếềểễệiíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵđÁÀẢẠÃĂẮẰẲẴẶÂẤẦẨẪẬÉÈẺẼẸÊẾỀỂỄỆIÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴĐ]';
LAST_WORD_REG2 = new RegExp(`(${CHAR_SET}+|\\S)$`);
LAST_ENGLISH_REG2= new RegExp(`${CHAR_SET}+$`);
FIRST_ENGLISH_REG2 = new RegExp(`^${CHAR_SET}`);


regexEqual(LAST_WORD_REG, LAST_WORD_REG2);
regexEqual(LAST_ENGLISH_REG, LAST_ENGLISH_REG2);
regexEqual(FIRST_ENGLISH_REG, FIRST_ENGLISH_REG2);

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

Copy link

github-actions bot commented Jan 29, 2025

👍 Package size ⤵ -1062 bytes, old: 5225108, new: 5224046

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -3959,16 +3959,16 @@
     export function fragmentText(stringToken: string, allWidth: number, maxWidth: number, measureText: (string: string) => number): string[];
     export const BASELINE_RATIO = 0.26;
     export const MIDDLE_RATIO: number;
     export class LRUCache {
-        constructor(size: any);
-        moveToHead(node: any): void;
-        put(key: any, value: any): void;
-        remove(node: any): void;
-        get(key: any): number | null;
+        constructor(size: number);
+        moveToHead(node: __private._cocos_2d_utils_text_utils__ICacheNode): void;
+        put(key: string, value: number): void;
+        remove(node: __private._cocos_2d_utils_text_utils__ICacheNode): void;
+        get(key: string): number | null;
         clear(): void;
-        has(key: any): boolean;
-        delete(key: any): void;
+        has(key: string): boolean;
+        delete(key: string): void;
     }
     /**
      * @en The dynamic atlas manager which manages all runtime dynamic packed atlas texture for UI rendering.
      * It generates a maximum of [[maxAtlasCount]] atlas texture, all atlas texture have the size of [[textureSize]].
@@ -61932,8 +61932,14 @@
              * @param {Number} y
              */
             drawTextureAt(image: ImageAsset, x: number, y: number): void;
         }
+        export interface _cocos_2d_utils_text_utils__ICacheNode {
+            key: string;
+            value: number;
+            prev: _cocos_2d_utils_text_utils__ICacheNode | null;
+            next: _cocos_2d_utils_text_utils__ICacheNode | null;
+        }
         /**
          * @en The instance of [[MorphRendering]] for dedicated control in the mesh renderer.
          * The root [[MorphRendering]] is owned by [[Mesh]] asset, each [[MeshRenderer]] can have its own morph rendering instance.
          * @zh 用于网格渲染器中独立控制 [[MorphRendering]] 的实例。原始 [[MorphRendering]] 被 [[Mesh]] 资源持有,每个 [[MeshRenderer]] 都持有自己的形变网格渲染实例。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant