为什么在Scala的标准库中@Specialized这么少的东西? [英] Why are so few things @specialized in Scala's standard library?

查看:227
本文介绍了为什么在Scala的标准库中@Specialized这么少的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Scala 2.8.1标准库的源代码中搜索了@specialized的用法.看起来只有少数特征和类使用此注释:Function0Function1Function2Tuple1Tuple2Product1Product2AbstractFunction0AbstractFunction1AbstractFunction2.

I've searched for the use of @specialized in the source code of the standard library of Scala 2.8.1. It looks like only a handful of traits and classes use this annotation: Function0, Function1, Function2, Tuple1, Tuple2, Product1, Product2, AbstractFunction0, AbstractFunction1, AbstractFunction2.

所有收集类都不是@specialized.为什么不?这样会产生太多的类吗?

None of the collection classes are @specialized. Why not? Would this generate too many classes?

这意味着使用具有原始类型的集合类的效率非常低,因为会进行很多不必要的装箱和拆箱操作.

This means that using collection classes with primitive types is very inefficient, because there will be a lot of unnecessary boxing and unboxing going on.

拥有Int的不可变列表或序列(具有IndexedSeq特征),避免装箱和拆箱的最有效方法是什么?

What's the most efficient way to have an immutable list or sequence (with IndexedSeq characteristics) of Ints, avoiding boxing and unboxing?

推荐答案

专业化在类的大小上具有很高的成本,因此必须仔细考虑添加.我认为在收藏的特殊情况下,影响将是巨大的.

Specialization has a high cost on the size of classes, so it must be added with careful consideration. In the particular case of collections, I imagine the impact will be huge.

这仍然是一项持续的工作-Scala库才刚刚开始专门化.

Still, it is an on-going effort -- Scala library has barely started to be specialized.

这篇关于为什么在Scala的标准库中@Specialized这么少的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆