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

[v3.8.6] Optimize code size by defining Constructor explicitly. #18119

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -45,6 +45,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 @@ -37,9 +37,9 @@
import { cache } from './utilities';
import { js } from '../../core';

export type CreateHandler = (id: string, data: any, options: Record<string, any>, onComplete: ((err: Error | null, data?: Asset | Bundle | null) => void)) => void;

Check warning on line 40 in cocos/asset/asset-manager/factory.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 163. Maximum allowed is 150

function createImageAsset (id: string, data: HTMLImageElement, options: Record<string, any>, onComplete: ((err: Error | null, data?: ImageAsset | null) => void)): void {

Check warning on line 42 in cocos/asset/asset-manager/factory.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 169. Maximum allowed is 150
let out: ImageAsset | null = null;
let err: Error | null = null;
try {
Expand All @@ -52,19 +52,19 @@
onComplete(err, out);
}

function createJsonAsset (id: string, data: Record<string, any>, options: Record<string, any>, onComplete: ((err: Error | null, data?: JsonAsset | null) => void)): void {

Check warning on line 55 in cocos/asset/asset-manager/factory.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 170. Maximum allowed is 150
const out = new JsonAsset();
out.json = data;
onComplete(null, out);
}

function createTextAsset (id: string, data: string, options: Record<string, any>, onComplete: ((err: Error | null, data?: TextAsset | null) => void)): void {

Check warning on line 61 in cocos/asset/asset-manager/factory.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 157. Maximum allowed is 150
const out = new TextAsset();
out.text = data;
onComplete(null, out);
}

function createBufferAsset (id: string, data: ArrayBufferView, options: Record<string, any>, onComplete: ((err: Error | null, data?: BufferAsset | null) => void)): void {

Check warning on line 67 in cocos/asset/asset-manager/factory.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 170. Maximum allowed is 150
const out = new BufferAsset();
out._nativeUrl = id;
out._nativeAsset = data;
Expand All @@ -78,7 +78,7 @@
onComplete(null, out);
}

function createBundle (id: string, data: IConfigOption, options: Record<string, any>, onComplete: ((err: Error | null, data?: Bundle | null) => void)): void {

Check warning on line 81 in cocos/asset/asset-manager/factory.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 158. Maximum allowed is 150
let bundle = bundles.get(data.name);
if (!bundle) {
bundle = data.name === BuiltinBundleName.RESOURCES ? resources : new Bundle();
Expand All @@ -96,7 +96,7 @@
}

export class Factory {
private _creating = new Cache<((err: Error | null, data?: any | null) => void)[]>();

Check failure on line 99 in cocos/asset/asset-manager/factory.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'any' overrides all other types in this union type

private _producers: Record<string, CreateHandler> = {
// Images
Expand Down Expand Up @@ -136,9 +136,10 @@
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 All @@ -147,7 +148,7 @@
}
}

public create (id: string, data: any, type: string, options: Record<string, any>, onComplete: ((err: Error | null, data?: Asset | Bundle | null) => void)): void {

Check warning on line 151 in cocos/asset/asset-manager/factory.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 166. Maximum allowed is 150
const handler = this._producers[type] || this._producers.default;
const asset = assets.get(id);
if (!options.reloadAsset && asset) {
Expand All @@ -164,7 +165,7 @@
handler(id, data, options, (err, result): void => {
if (!err && result instanceof Asset) {
result._uuid = id;
cache(id, result, options.cacheAsset);

Check failure on line 168 in cocos/asset/asset-manager/factory.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `boolean | undefined`
}
const callbacks = this._creating.remove(id);
for (let i = 0, l = callbacks!.length; i < l; i++) {
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 @@ -325,8 +325,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 @@ -31,9 +31,11 @@
const targetSymbol = Symbol('[[target]]');

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 @@ -52,7 +52,10 @@
* @en GFX Device.
* @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
Loading