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

Optimization for xlua_hotfix_flags #1069

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
68 changes: 39 additions & 29 deletions Assets/Plugins/iOS/HotfixFlags.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

int* xlua_hotfix_flags = NULL;
bool* xlua_hotfix_flags = NULL;
int xlua_hotfix_flags_len = 0;

extern "C" {
extern "C"
{
int xlua_get_hotfix_flag(int idx)
{
if (idx >= xlua_hotfix_flags_len)
{
return 0;
}
else
{
return xlua_hotfix_flags[idx];
}
}

int xlua_get_hotfix_flag(int idx) {
if (idx >= xlua_hotfix_flags_len) {
return 0;
} else {
return xlua_hotfix_flags[idx];
}
}
void xlua_set_hotfix_flag(int idx, int flag)
{
if (idx >= xlua_hotfix_flags_len)
{
bool* new_hotfix_flags = (bool*)malloc(idx + 1);

void xlua_set_hotfix_flag(int idx, int flag) {
int i = 0;
int* new_hotfix_flags = NULL;
if (idx >= xlua_hotfix_flags_len) {
if (xlua_hotfix_flags == NULL) {
xlua_hotfix_flags = (int*)malloc((idx + 1) * sizeof(int));
} else {
new_hotfix_flags = (int*)realloc(xlua_hotfix_flags, (idx + 1) * sizeof(int));
if (NULL == new_hotfix_flags) { // just skip operation
return;
}
xlua_hotfix_flags = new_hotfix_flags;
}
for(i = xlua_hotfix_flags_len; i < (idx + 1); i++) {
xlua_hotfix_flags[i] = 0;
}
xlua_hotfix_flags_len = idx + 1;
}
xlua_hotfix_flags[idx] = flag;
}
if (xlua_hotfix_flags == NULL)
{
memset(new_hotfix_flags, 0, (idx + 1));
xlua_hotfix_flags = new_hotfix_flags;
}
else
{
memcpy(new_hotfix_flags, xlua_hotfix_flags, xlua_hotfix_flags_len);
memset(new_hotfix_flags + xlua_hotfix_flags_len, 0, (idx + 1 - xlua_hotfix_flags_len));
bool* tmp = xlua_hotfix_flags;
xlua_hotfix_flags = new_hotfix_flags;
free(tmp);
}

xlua_hotfix_flags_len = idx + 1;
}

xlua_hotfix_flags[idx] = flag;
}
}
13 changes: 12 additions & 1 deletion Assets/XLua/Src/DelegateBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,21 @@ public static void Set(int idx, DelegateBridge val)
}
DelegateBridge.DelegateBridgeList = newList;
}

#if (UNITY_IPHONE || UNITY_TVOS) && !UNITY_EDITOR
if (val == null)
{
xlua_set_hotfix_flag(idx, false);
}
#endif
DelegateBridge.DelegateBridgeList[idx] = val;
#if (UNITY_IPHONE || UNITY_TVOS) && !UNITY_EDITOR
xlua_set_hotfix_flag(idx, val != null);
if (val != null)
{
xlua_set_hotfix_flag(idx, true);
}
#endif

}
}

Expand Down