Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
db2bcb4e
Commit
db2bcb4e
authored
Dec 30, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance performance: no redundant lambda creation when constructing Bot
parent
e37ace91
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
10 deletions
+28
-10
mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/TIMPC.kt
...impc/src/commonMain/kotlin/net.mamoe.mirai.timpc/TIMPC.kt
+1
-2
mirai-core-timpc/src/jvmTest/kotlin/PacketDebugger.kt
mirai-core-timpc/src/jvmTest/kotlin/PacketDebugger.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotFactory.kt
...-core/src/commonMain/kotlin/net.mamoe.mirai/BotFactory.kt
+15
-3
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotFactoryJvm.kt
...-core/src/jvmMain/kotlin/net/mamoe/mirai/BotFactoryJvm.kt
+10
-3
mirai-demos/mirai-demo-1/src/main/java/demo/subscribe/SubscribeSamples.kt
...i-demo-1/src/main/java/demo/subscribe/SubscribeSamples.kt
+1
-1
No files found.
mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/TIMPC.kt
View file @
db2bcb4e
...
...
@@ -15,6 +15,5 @@ object TIMPC : BotFactory {
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
override
fun
Bot
(
account
:
BotAccount
,
configuration
:
(
BotConfiguration
.()
->
Unit
)?):
Bot
=
TIMPCBot
(
account
,
if
(
configuration
==
null
)
BotConfiguration
.
Default
else
BotConfiguration
().
apply
(
configuration
))
override
fun
Bot
(
account
:
BotAccount
,
configuration
:
BotConfiguration
):
Bot
=
TIMPCBot
(
account
,
configuration
)
}
\ No newline at end of file
mirai-core-timpc/src/jvmTest/kotlin/PacketDebugger.kt
View file @
db2bcb4e
...
...
@@ -382,7 +382,7 @@ when (idHex.substring(0, 5)) {
internal
object
DebugNetworkHandler
:
BotNetworkHandler
(),
CoroutineScope
{
override
val
supervisor
:
CompletableJob
=
SupervisorJob
()
override
val
bot
:
Bot
=
TIMPC
.
Bot
(
qq
?:
0L
,
""
,
null
)
override
val
bot
:
Bot
=
TIMPC
.
Bot
(
qq
?:
0L
,
""
)
override
suspend
fun
login
()
{}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotFactory.kt
View file @
db2bcb4e
...
...
@@ -15,11 +15,23 @@ interface BotFactory {
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
fun
Bot
(
account
:
BotAccount
,
configuration
:
(
BotConfiguration
.()
->
Unit
)?
=
null
):
Bot
fun
Bot
(
account
:
BotAccount
,
configuration
:
BotConfiguration
=
BotConfiguration
.
Default
):
Bot
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
fun
Bot
(
qq
:
Long
,
password
:
String
,
configuration
:
(
BotConfiguration
.()
->
Unit
)?
=
null
):
Bot
=
fun
Bot
(
qq
:
Long
,
password
:
String
,
configuration
:
BotConfiguration
=
BotConfiguration
.
Default
):
Bot
=
this
.
Bot
(
BotAccount
(
qq
,
password
),
configuration
)
}
\ No newline at end of file
}
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
inline
fun
BotFactory
.
Bot
(
account
:
BotAccount
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
this
.
Bot
(
account
,
BotConfiguration
().
apply
(
configuration
))
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
inline
fun
BotFactory
.
Bot
(
qq
:
Long
,
password
:
String
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
this
.
Bot
(
qq
,
password
,
BotConfiguration
().
apply
(
configuration
))
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotFactoryJvm.kt
View file @
db2bcb4e
...
...
@@ -5,7 +5,8 @@ package net.mamoe.mirai
import
net.mamoe.mirai.utils.BotConfiguration
// Do not use ServiceLoader. Probably not working on MPP
private
val
factory
=
run
{
@PublishedApi
internal
val
factory
:
BotFactory
=
run
{
try
{
Class
.
forName
(
"net.mamoe.mirai.timpc.TIMPC"
).
kotlin
.
objectInstance
as
BotFactory
}
catch
(
ignored
:
Exception
)
{
...
...
@@ -23,11 +24,17 @@ private val factory = run {
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
fun
Bot
(
account
:
BotAccount
,
configuration
:
(
BotConfiguration
.()
->
Unit
)?
=
null
):
Bot
=
fun
Bot
(
account
:
BotAccount
,
configuration
:
BotConfiguration
=
BotConfiguration
.
Default
):
Bot
=
factory
.
Bot
(
account
,
configuration
)
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
fun
Bot
(
qq
:
Long
,
password
:
String
,
configuration
:
(
BotConfiguration
.()
->
Unit
)?
=
null
):
Bot
=
inline
fun
Bot
(
account
:
BotAccount
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
factory
.
Bot
(
account
,
configuration
)
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
inline
fun
Bot
(
qq
:
Long
,
password
:
String
,
configuration
:
(
BotConfiguration
.()
->
Unit
)):
Bot
=
factory
.
Bot
(
qq
,
password
,
configuration
)
\ No newline at end of file
mirai-demos/mirai-demo-1/src/main/java/demo/subscribe/SubscribeSamples.kt
View file @
db2bcb4e
...
...
@@ -38,7 +38,7 @@ private fun readTestAccount(): BotAccount? {
@Suppress
(
"UNUSED_VARIABLE"
)
suspend
fun
main
()
{
val
bot
=
TIMPC
.
Bot
(
val
bot
=
TIMPC
.
Bot
(
// JVM 下也可以不写 `TIMPC.` 引用顶层函数
readTestAccount
()
?:
BotAccount
(
//填写你的账号
id
=
1994701121
,
passwordPlainText
=
"123456"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment