inline

Inlining this function or not?

我是研究僧i 提交于 2019-12-07 12:22:57
问题 I'm supposed to implement a function which compares two strings simliar so strcmp but ignoring whitespace characters, so strcmpignorews("abc ", " a b c") should give the same result. Here's my implementation: namespace { void SkipWhitespace(const char *&s) { for (; std::isspace(*s, std::locale::classic); ++s); } } int strcmpignorews(const char *s1, const char *s2) { for (; *s1 != '\0' && *s2 != '\0'; ++s1, ++s2) { SkipWhitespace(s1); SkipWhitespace(s2); if (*s1 != *s2) { break; } } return (

Inline ntohs() / ntohl() in C++ / Boost ASIO

妖精的绣舞 提交于 2019-12-07 11:57:00
问题 Hi I'm using C++ / Boost ASIO and I have to inline ntohl() for performance reasons. Each data packet contains 256 int32s, hence a lot of calls to ntohl() . Has anyone done this? Here is the compiled assembly output out of VC10++ with all optimizations turned on: ; int32_t d = boost::asio::detail::socket_ops::network_to_host_long(*pdw++); mov esi, DWORD PTR _pdw$[esp+64] mov eax, DWORD PTR [esi] push eax call DWORD PTR __imp__ntohl@4 I've also tried the regular ntohl() provided by winsock. Any

Luogu P1972 [SDOI2009]HH的项链

限于喜欢 提交于 2019-12-07 11:19:46
很 清新自然 凶猛 的数据结构题,都是 套路 啊 我们可以考虑 离线 做,先把区间按右端点从小到大排序 首先注意到一种贝壳如果在一段中出现超过1次,那么它在前面或后面就无关紧要了 举一个例子: 对于数列1 2 3 1如果我的右端点已经扫描到第四位了,那么第一位的1就可以删掉了(因为按右端点排了序) 所以我们开 树状数组 维护一个位置上是否有 有效 的颜色,即对于上一个例子2,3,4位上是有有效的颜色的 然后对于每一个操作,我们求出x,y这段区间内1的个数即可,树状数组减一发即可 具体看代码 #include<cstdio> #include<algorithm> using namespace std; const int N=500005,M=200005,MAX_NUM=1000005; struct ques { int x,y,num; }q[M]; int tree[N],a[N],num[MAX_NUM],ans[M],n,m,now; inline char tc(void) { static char fl[100000],*A=fl,*B=fl; return A==B&&(B=(A=fl)+fread(fl,1,100000,stdin),A==B)?EOF:*A++; } inline void read(int &x) { x=0; char ch=tc()

Why is my Trie lookup slower than that of the standard F# Map's?

帅比萌擦擦* 提交于 2019-12-07 08:19:09
问题 So, I just ported the Trie from OCaml. Unfortunately, it runs slower than the standard Map in terms of tryFind. I don't understand this - the trie seems like it should be faster. Is F#'s code libraries built in some special way as to make them faster than the code that the user typically deploys? Here's the code - [<RequireQualifiedAccess>] module Trie type Node<'k, 'v when 'k : comparison> = { TrieMap : Map<'k, Node<'k, 'v>> TrieKvp : ('k list * 'v) option } member inline x.IsEmpty = x

Stack Trace for logging in .NET

荒凉一梦 提交于 2019-12-07 07:37:00
问题 I've written a logger/exceptionfactory module, which uses System.Diagnostics.StackTrace, to get attributes from calling methods and their declaring types. However I noticed, that if I run the code outside of Visual Studio in Release mode, some of my shorter methods get inlined and missing from the stack trace. Now I have no way to test whether a method will get inlined in runtime, but I do not want to [MethodImpl(MethodImplOptions.NoInlining)] every important method. But if a method from my

What are the inlining rules within C++ classes?

杀马特。学长 韩版系。学妹 提交于 2019-12-07 07:05:30
问题 From what I read somewhere long time ago, it seems that if you want class member function to be inlined during the compilation phase, the function has to be defined inside class declaration block. But this has a downside of a detail leak. IMHO, other programmers should only see class interface when opening .h file. Is the first statement still true in modern C++, was it ever? Is there a way to force inlining for functions that are declared, preferably in another file altogether? Is it

jqgrid inline edit - Save handler when clicking enter

拟墨画扇 提交于 2019-12-07 01:51:27
Im wondering if there is an event handler for the save method when clicking enter to save the row. I want to use it to hide the row from the grid after being saved. thanks in advance! Both editRow and saveRow inline editing methods has succesfunc and aftersavefunc parameters which you can use. The aftersavefunc has small advantage because it is used in both local and remote holding of the grid data. So the code can be ondblClickRow: function (rowid) { $(this).jqGrid('editRow', rowid, true, null, null, null, {}, function (rowid) { $(this.rows.namedItem(rowid)).hide(); $(this).focus(); // set

Linker error inline function

杀马特。学长 韩版系。学妹 提交于 2019-12-07 01:34:07
问题 I got some compiler/linker errors and i don't know what is the correct method to proceed. I'm in this situation: a.h: in this file is defined a function declared as "inline", for example: inline void foo1(); b.h: in this file is defined a function declared as "inline" that calls foo1(): inline void foo2(); main.c: there are some functions calls of both foo1 and foo2(). Now, if i declare foo1 and foo2 in a.h and b.h as extern inline void i got the following error: prj/src/b.o: In function foo1

How do I use scipy.weave.inline together with external C libraries?

半腔热情 提交于 2019-12-07 01:31:08
问题 I am trying to understand weave.inline to wrap C code in my Python programs. The code below simply takes the Numpy array and multiplicates all of its elements by 2. inl.py import numpy import scipy.weave a = numpy.array([1.0, 2.0, 3.0]) N = a.shape[0] print a code = \ """ int i; for(i = 0; i < N; i++) { a[i] = a[i] * 2; } """ scipy.weave.inline(code, ['a','N']) print a Then I want to carry some functions from inline code to external libraries. Let it be the trivial multiplication by 2. So I

Can a compiler inline a virtual function if I use a pointer in a clear situation?

倾然丶 夕夏残阳落幕 提交于 2019-12-06 22:10:03
问题 I've already read Are inline virtual functions really a non-sense?. But I still have some doubts and found no answer there. They say that if situation isn't ambiguous, compiler should inline the virtual function . However: This can happen only when the compiler has an actual object rather than a pointer or reference to an object. So what if I have a B class derived from an A one (which contains a virtual void doSth() function) and I use the B* pointer, not the A* : B* b = new B; b->doSth();