inline

Make method actually inline

依然范特西╮ 提交于 2019-12-22 05:12:20
问题 I forge a simple example to check the @inline annotation behavior: import scala.annotation.tailrec object InlineTest extends App { @inline private def corec(x : Int) : Int = rec(x - 1) @tailrec private def rec(x : Int) : Int = if (x < 3) x else { if (x % 3 == 0) corec(x-1) else rec(x-4) } @tailrec private def rec1(x : Int) : Int = if (x < 3) x else { if (x % 3 == 0) { val arg = x - 1 rec1(arg - 1) } else rec1(x-4) } Console.println( rec(args(0).toInt) ) } This example compiled without

Make method actually inline

橙三吉。 提交于 2019-12-22 05:11:26
问题 I forge a simple example to check the @inline annotation behavior: import scala.annotation.tailrec object InlineTest extends App { @inline private def corec(x : Int) : Int = rec(x - 1) @tailrec private def rec(x : Int) : Int = if (x < 3) x else { if (x % 3 == 0) corec(x-1) else rec(x-4) } @tailrec private def rec1(x : Int) : Int = if (x < 3) x else { if (x % 3 == 0) { val arg = x - 1 rec1(arg - 1) } else rec1(x-4) } Console.println( rec(args(0).toInt) ) } This example compiled without

Difference between using fully qualified name and import in Java

孤人 提交于 2019-12-22 05:06:16
问题 Are there any differences using an "inline import" (a fully qualified name) and normal import in terms of performance, memory, compile-time, etc. in Java? chooser.setCurrentDirectory(new java.io.File(".")); and import java.io.File; ... chooser.setCurrentDirectory(new File(".")); 回答1: The main thing you should focus in is readability. I find the second one more readable. In rare cases, I prefer the second approach. Let's consider the following scenario: For some reason, I wrote a class and

Kotlin inlined extension property

无人久伴 提交于 2019-12-22 04:37:07
问题 I know inline keyword means to avoid the call overhead calling a funtion. But I can't figure out what inline a extension property work for? Let say we have two extension property named foo and another with is inlined named bar val Any.foo : Long get() = Date().time inline val Any.bar : Long get() = Date().time Executing any of them, we gent the expected output, the current time. The bytecode for this file is this below: public final class InlinedExtensionPropertyKt { public final static

Are the default constructor and destructor ever inline?

本小妞迷上赌 提交于 2019-12-22 04:08:34
问题 I'm curious if the default constructor and destructor that the compiler generates are inline or not, because I can justify it either way. On the one hand, you want the default constructor/destructor to not be inline so that adding them later doesn't break ABI (because object files compiled when only the defaults were there will have inlined the generated definitions instead of what you define). On the other hand, for a C++ compiler to compile C code that performs as well as when compiled with

inline function in namespace generate duplicate symbols during link on gcc

十年热恋 提交于 2019-12-22 04:06:51
问题 I have a namespace with inline function that will be used if several source files. When trying to link my application, the inline function are reported as duplicate symbols. It seems as if my code would simply not inline the functions and I was wondering if this is the expected behavior and how to best deal with it. I use the following gcc options: -g -Wextra -pedantic -Wmissing-field-initializers -Wredundant-decls -Wfloat-equal -Wno-reorder -Wno-long-long The same code style seems to compile

Forward declaration of inline functions

眉间皱痕 提交于 2019-12-22 01:37:58
问题 I have a header file that is going to contain a large amount (30+) of inline functions. Rather than having the reader scroll or search for the definition (implementation) of the inline function, I would like to have a forward declaration section that states the function declaration with comments describing the function. This section would allow the reader to find out how to use a function or to look for a function without having to scroll down to the implementation. Also, I would like the

Twitter-Bootstrap - put simple elements inline

我怕爱的太早我们不能终老 提交于 2019-12-22 01:24:34
问题 Is there anyway to put 2 <a> elements displaying inline? i tryed : <div class="form-inline"> <a>jjj</a> <a>sss</a> </div> and also <div class="row-fluid"> <a class="inline">jjj</a> <a class="inline">sss</a> </div> but it doesn't work. 回答1: Anchor tags by default should be displayed inline . You must have some extra styling setting them to display as block elements or something similar. Using your code, here is a working JSFiddle. Inspect your page to find out where the anchor's display is

平衡树之Splay

烈酒焚心 提交于 2019-12-21 22:17:22
算法简介 Splay是一种平衡树,支持插入、删除、求排名、求第 \(k\) 大数、求前驱和求后继的操作,并且它还能做到一般平衡树做不到的区间操作。 定义与性质 先说二叉查找树:就是把所有数建在树上,且左边的数永远小于右边的。 对于上面说的那6个操作,其实在数据随机时二叉查找树时最强的,但是数据一条链你就Good Game了。 这种情况我们希望这棵二叉查找树的节点深度差不要太大,这就有了平衡树。 顾名思义,平衡树是平衡的二叉查找树,意思就是说1条链这种数据对于平衡树来说完全不存在,这样复杂度就有保证了。 基础操作 核心操作 这些都是很重要的操作,直接维护了Splay的平衡。 pushup 维护子树大小,很简单,不谈。好像只在旋转操作中出现。 inline void pushup(int x) { siz[x]=siz[ch[x][0]]+siz[ch[x][1]]+ct[x]; } 左右旋 核心中的核心,是另外一个核心操作的基础核心操作。 这个东西可以改变两个相邻节点的父子关系,并且仍然满足平衡树的性质。给张图,就可以看明白了。 inline void rota(int x) { int y=ff[x],z=ff[y],k=(x==ch[y][1]); ch[z][y==ch[z][1]]=x; ff[x]=z; ch[y][k]=ch[x][k^1]; ff[ch[x][k^1]]

Kotlin let操作符

自古美人都是妖i 提交于 2019-12-21 11:14:57
let扩展函数的实际上是一个作用域函数,当你需要去定义一个变量在一个特定的作用域范围内,let函数的是一个不错的选择;let函数另一个作用就是可以避免写一些判断null的操作。 1、let函数的使用的一般结构 object.let{ it.todo()//在函数体内使用it替代object对象去访问其公有的属性和方法 ... } //另一种用途 判断object为null的操作 object?.let{//表示object不为null的条件下,才会去执行let函数体 it.todo() } 2、let函数底层的inline扩展函数+lambda结构 @kotlin.internal.InlineOnly public inline fun <T, R> T.let(block: (T) -> R): R = block(this) 1 2 3、let函数inline结构的分析 从源码let函数的结构来看它是只有一个lambda函数块block作为参数的函数,调用T类型对象的let函数,则该对象为函数的参数。在函数块内可以通过 it 指代该对象。返回值为函数块的最后一行或指定return表达式。 4、let函数的kotlin和Java转化 //kotlin fun main(args: Array<String>) { val result = "testLet".let {