Skip to content

Commit

Permalink
[v3.8.6] Optimize code size by defining Constructor explicitly. (#18119)
Browse files Browse the repository at this point in the history
* [v3.8.6] Optimize code size by defining Constructor explicitly.
  • Loading branch information
dumganhar authored Jan 13, 2025
1 parent 52ab800 commit 515244b
Show file tree
Hide file tree
Showing 42 changed files with 113 additions and 37 deletions.
3 changes: 3 additions & 0 deletions cocos/2d/assembler/label/font-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export class CanvasPool {
}
return _canvasPool;
}

private constructor () {}

public pool: ISharedLabelData[] = [];
public get (): ISharedLabelData {
let data = this.pool.pop();
Expand Down
3 changes: 3 additions & 0 deletions cocos/2d/assets/font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import { cclegacy } from '../../core';
*/
@ccclass('cc.Font')
export class Font extends Asset {
constructor (name?: string) {
super(name);
}
}

cclegacy.Font = Font;
4 changes: 2 additions & 2 deletions cocos/2d/assets/sprite-atlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export class SpriteAtlas extends Asset {
@editable
public spriteFrames: ISpriteFrameList = js.createMap();

constructor () {
super();
constructor (name?: string) {
super(name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/assets/sprite-frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ export class SpriteFrame extends Asset {
protected _minPos = v3();
protected _maxPos = v3();

constructor () {
super();
constructor (name?: string) {
super(name);

if (EDITOR) {
// Atlas asset uuid
Expand Down
4 changes: 2 additions & 2 deletions cocos/3d/assets/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ export class Mesh extends Asset {

private _jointBufferIndices: number[] | null = null;

constructor () {
super();
constructor (name?: string) {
super(name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cocos/3d/assets/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class Skeleton extends Asset {

private _invBindposes: Mat4[] | null = null;

constructor () {
super();
constructor (name?: string) {
super(name);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions cocos/3d/misc/buffer-blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class BufferBlob {
private _arrayBufferOrPaddings: Array<ArrayBuffer | number> = [];
private _length = 0;

constructor () {}

public setNextAlignment (align: number): void {
if (align !== 0) {
const remainder = this._length % align;
Expand Down
4 changes: 4 additions & 0 deletions cocos/animation/animation-clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ export class AnimationClip extends Asset {
@serializable
public enableTrsBlending = false;

constructor (name?: string) {
super(name);
}

/**
* @zh 动画的周期。
* @en Animation duration.
Expand Down
2 changes: 2 additions & 0 deletions cocos/asset/asset-manager/builtin-res-mgr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class BuiltinResMgr {
protected _resources: Record<string, Asset> = {};
protected _materialsToBeCompiled: Material[] = [];

constructor () {}

// this should be called after renderer initialized
public init (): void {
const resources = this._resources;
Expand Down
2 changes: 2 additions & 0 deletions cocos/asset/asset-manager/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import type { AssetManager } from './asset-manager';
export default class Bundle {
private _config: Config = new Config();

constructor () {}

/**
* For internal use.
* @engineInternal
Expand Down
3 changes: 2 additions & 1 deletion cocos/asset/asset-manager/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ export class Factory {
bundle: createBundle,

default: createAsset,

};

constructor () {}

public register (type: string | Record<string, CreateHandler>, handler?: CreateHandler): void {
if (typeof type === 'object') {
js.mixin(this._producers, type);
Expand Down
2 changes: 1 addition & 1 deletion cocos/asset/assets/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class Asset extends Eventify(CCObject) {
return this._file;
}

constructor (name = '') {
constructor (name?: string) {
super(name);

Object.defineProperty(this, '_uuid', {
Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/assets/buffer-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import { Asset } from './asset';
export class BufferAsset extends Asset {
private _buffer: ArrayBuffer | null = null;

constructor () {
super();
constructor (name?: string) {
super(name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/assets/effect-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ export class EffectAsset extends Asset {
@editorOnly
public hideInEditor = false;

constructor () {
super();
constructor (name?: string) {
super(name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/assets/json-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default class JsonAsset extends Asset {
@editable
public json: Record<string, any> | null = null;

constructor () {
super();
constructor (name?: string) {
super(name);
}
}

Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/assets/material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ export class Material extends Asset {
*/
protected _hash = 0;

constructor () {
super();
constructor (name?: string) {
super(name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/assets/render-texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ const _windowInfo: IRenderWindowInfo = {
@ccclass('cc.RenderTexture')
export class RenderTexture extends TextureBase {
private _window: RenderWindow | null = null;
constructor () {
super();
constructor (name?: string) {
super(name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/assets/scene-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class SceneAsset extends Asset {
@serializable
public scene: Scene | null = null;

constructor () {
super();
constructor (name?: string) {
super(name);
}

public initDefault (uuid?: string): void {
Expand Down
9 changes: 9 additions & 0 deletions cocos/asset/assets/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import { cclegacy } from '../../core';
*/
@ccclass('cc.Script')
export class Script extends Asset {
constructor (name?: string) {
super(name);
}
}
cclegacy._Script = Script;

Expand All @@ -42,6 +45,9 @@ cclegacy._Script = Script;
*/
@ccclass('cc.JavaScript')
export class JavaScript extends Script {
constructor (name?: string) {
super(name);
}
}
cclegacy._JavaScript = JavaScript;

Expand All @@ -51,5 +57,8 @@ cclegacy._JavaScript = JavaScript;
*/
@ccclass('cc.TypeScript')
export class TypeScript extends Script {
constructor (name?: string) {
super(name);
}
}
cclegacy._TypeScript = TypeScript;
4 changes: 2 additions & 2 deletions cocos/asset/assets/simple-texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export class SimpleTexture extends TextureBase {
*/
protected _maxLevel = 1000;

constructor () {
super();
constructor (name?: string) {
super(name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/assets/text-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export class TextAsset extends Asset {
return this.text;
}

constructor () {
super();
constructor (name?: string) {
super(name);
}
}

Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/assets/texture-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export interface ITexture2DCreateInfo {
*/
@ccclass('cc.Texture2D')
export class Texture2D extends SimpleTexture {
constructor () {
super();
constructor (name?: string) {
super(name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/assets/texture-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ export class TextureBase extends Asset {

private _textureHash = 0;

constructor () {
super();
constructor (name?: string) {
super(name);

// Id for generate hash in material
this._id = idGenerator.getNewId();
Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/assets/texture-cube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export class TextureCube extends SimpleTexture {
@serializable
_mipmapMode = MipmapMode.NONE;

constructor () {
super();
constructor (name?: string) {
super(name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cocos/audio/audio-clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export class AudioClip extends Asset {

private _player: AudioPlayer | null = null;

constructor () {
super();
constructor (name?: string) {
super(name);
}

public destroy (): boolean {
Expand Down
2 changes: 2 additions & 0 deletions cocos/core/data/garbage-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class GarbageCollectionManager {
private _finalizationRegistry: FinalizationRegistry | null = EDITOR && typeof FinalizationRegistry !== 'undefined' ? new FinalizationRegistry(this.finalizationRegistryCallback.bind(this)) : null;

Check warning on line 34 in cocos/core/data/garbage-collection.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 199. Maximum allowed is 150
private _gcObjects: WeakMap<any, GCObject> = new WeakMap();

constructor () {}

public registerGCObject (gcObject: GCObject): GCObject {
if (EDITOR && this._finalizationRegistry) {
const token = {};
Expand Down
6 changes: 6 additions & 0 deletions cocos/core/event/callbacks-invoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class CallbackInfo {
public target: unknown = undefined;
public once = false;

constructor () {}

public set (callback: AnyFunction, target?: unknown, once?: boolean): void {
this.callback = callback || empty;
this.target = target;
Expand Down Expand Up @@ -70,6 +72,8 @@ export class CallbackList {
public isInvoking = false;
public containCanceled = false;

constructor () {}

/**
* @zh 从列表中移除与指定目标相同回调函数的事件。
* @en Remove the event listeners with the given callback from the list
Expand Down Expand Up @@ -186,6 +190,8 @@ export class CallbacksInvoker<EventTypeClass extends EventType = EventType> {
public _callbackTable: ICallbackTable = createMap(true);
private _offCallback?: () => void;

constructor () {}

/**
* @zh 向一个事件名注册一个新的事件监听器,包含回调函数和调用者
* @en Register an event listener to a given event key with callback and target.
Expand Down
2 changes: 2 additions & 0 deletions cocos/core/memop/scalable-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class ScalableContainerManager {
*/
public shrinkTimeSpan = 5;

constructor () {}

/**
* @en Add a ScalableContainer. Will add the same ScalableContainer instance once.
* @param pool @en The ScalableContainer to add.
Expand Down
2 changes: 2 additions & 0 deletions cocos/core/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export enum SettingsCategory {
export class Settings {
static Category = SettingsCategory;

constructor () {}

/**
* Initialization
* @internal
Expand Down
1 change: 1 addition & 0 deletions cocos/core/value-types/value-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { legacyCC } from '../global-exports';
* @zh 所有值类型的基类。
*/
export class ValueType {
constructor () {}
/**
* @en
* Clone the current object. The clone result of the object should be equal to the current object,
Expand Down
3 changes: 3 additions & 0 deletions cocos/gfx/base/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ import { Swapchain } from './swapchain';
* @zh GFX 设备。
*/
export abstract class Device {

Check failure on line 55 in cocos/gfx/base/device.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Block must not be padded by blank lines

constructor () {}

/**
* @en Current rendering API.
* @zh 当前 GFX 使用的渲染 API。
Expand Down
3 changes: 3 additions & 0 deletions cocos/gfx/device-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ export class DeviceManager {
private _swapchain!: Swapchain;
private _renderType: RenderType = RenderType.UNKNOWN;
private _deviceInitialized = false;

constructor () {}

public get gfxDevice (): Device {
return this._gfxDevice;
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/particle-2d/particle-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const { ccclass, serializable, editable } = _decorator;
export class ParticleAsset extends Asset {
@serializable
@editable
public spriteFrame: SpriteFrame | null= null;
public spriteFrame: SpriteFrame | null = null;
}

cclegacy.ParticleAsset = ParticleAsset;
1 change: 1 addition & 0 deletions cocos/render-scene/scene/fog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const FOG_TYPE_NONE = FogType.LAYERED + 1;
* @zh 渲染场景中的全局雾效配置
*/
export class Fog {
constructor () {}
/**
* @zh 是否启用全局雾效
* @en Enable global fog
Expand Down
2 changes: 2 additions & 0 deletions cocos/render-scene/scene/submodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class SubModel {
protected _instancedSHIndex = -1;
protected _useReflectionProbeType = 0;

constructor () {}

/**
* @en
* sub model's passes
Expand Down
1 change: 1 addition & 0 deletions cocos/rendering/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ localDescriptorSetLayout.bindings[UBOMorph.BINDING] = UBOMorph.DESCRIPTOR;

// UI local uniform UBO
export class UBOUILocal { // pre one vec4
private constructor () {}
public static readonly NAME = 'CCUILocal';
public static readonly BINDING = ModelLocalBindings.UBO_UI_LOCAL;
public static readonly DESCRIPTOR = new DescriptorSetLayoutBinding(UBOUILocal.BINDING, DescriptorType.DYNAMIC_UNIFORM_BUFFER, 1, ShaderStageFlagBit.VERTEX);
Expand Down
Loading

0 comments on commit 515244b

Please sign in to comment.